how to resolve iframe cross domain issue [duplicate]

微笑、不失礼 提交于 2019-12-30 04:31:06

问题


I'm making web page that has to show another domain's web page.

For example, in my web html, there are two <div> tags.

Like :

<html>
<head></head>
<body>
   <div>
      <p> hello world </p>
   </div>
   <div>
      <!-- other domain's web page comes here -->
   </div> 
</body>
</html>

To resolve my issue, I should use <iframe>, <embed> or <object> tags, but this causes the cross domain problem. So, I can't use it to show other domain's web page. They doesn't allow me to use it.

So, for example :

<iframe src="http://stackoverflow.com"></iframe>

It doesn't work. My web page can't show stackoverflow.com. Because, stackoverflow denies this.

I have searched lots of things with these issues. But they are just ajax or JSONP. It was not iframe.

Are there solutions to resolve my problem?? Or is it impossible to implement this?


回答1:


You need control over the domain you want to embed to remove/amend its CORS policy. It the domain has explicitely blocked Cross-Origin requests, there's nothing you can do about it.

This is used to avoid anyone hijacking any site you want (you could have a full screen Google in an iframe running with your ads on top on bettergoogle.com, things like that).

This page will give you more insights on Cross-Origin




回答2:


If you have the permission of the owner of the domain in the iframe, you can ask them to add your domain to their cross-origin policies so you can do this.

If you don't have permission to show their content on your site, I'm happy to say that modern browsers do not support such unethical behaviour, and there is no way of doing what you are trying to do.



来源:https://stackoverflow.com/questions/40866219/how-to-resolve-iframe-cross-domain-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!