Keeping pages inside an iframe

2019-08-22 10:51发布

I am trying to put a website inside an iframe, but this code on the site keeps changing the window of the page. Is there anyway I can get around this? Or better yet, can I disable javascript in an iframe?

if(top!=self){
  if(top.location)
    top.location=self.location;
  else
    top.location='http://example.com/not_subframe.html';
}

5条回答
▲ chillily
2楼-- · 2019-08-22 11:09

You can only access the content of one frame from within another frame if both frames are from the same domain.

Otherwise this would be an XSS issue which is therefore forbidden by a browser.

查看更多
劫难
3楼-- · 2019-08-22 11:14

iFrames have a variety of security features to try to block what you're doing.

查看更多
放荡不羁爱自由
4楼-- · 2019-08-22 11:18

Nope, can't be done. Not to mention it's usually a bad practice.

查看更多
Explosion°爆炸
5楼-- · 2019-08-22 11:25

Web pages cannot disable JavaScript, if they could, it would be mayhem.

查看更多
SAY GOODBYE
6楼-- · 2019-08-22 11:26

Yes it is possible, there are several methods of anti-frame busting including disabling JS in a frame (sandboxing, designMode). All described in Limitations of OWASP:Defending_with_Frame_Breaking_Scripts.

Generally use it only with intranet or restricted access site. If you expose site publicly with such tricks you may expect blacklisting by Google or others.

查看更多
登录 后发表回答