更改iframe网址更改父窗口网址 [英] changing iframe url changes parent window url

查看:197
本文介绍了更改iframe网址更改父窗口网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用下一页在iframe中显示url的内容,并根据输入值对其进行更改.

i'm using following page to display content of a url in a iframe and changing it based on input value .

<html>
<head>
<script type="text/javascript">
function changeUrl()
{
 var url=document.getElementById('browseurl').value;
 if(url!="")
 {
   if(url.indexOf("http")==-1)
   {
    url="http://"+url;
   }
   document.getElementById('browserWnd').src=url;
 }
}
</script>
</head>

<body>
 <div >
   <span>Url</span> 
   <input id="browseurl" name="browseurl" type='textbox' />
   <input id="browse" type='button' value="changeurl" onclick="changeUrl()" />
 </div>

<iframe id="browserWnd" src="http://www.coolmath.com/" height="700" width="625"></iframe>
</div>
</body>
</html>

我的问题是浏览iframe中加载的URL的某些内部页面 更改父窗口URL ,而不是iframe中加载...

my problem is browsing some inner pages of an url loaded in iframe changes the parent window url instead of loading in iframe ...

以前的 http://www.coolmath.com/会加载到iframe中,但在浏览某些链接时会在父窗口中加载整个页面.

for ex http://www.coolmath.com/ load in iframe but while browsing some links loads the entire page in parent window.

推荐答案

您可能会注意到,即使像这样的<iframe src='http://www.coolmath-games.com/0-fraction-splat/index.html'></iframe>也会产生相同的结果.这是一种称为框架破坏的技术.在他们页面的代码中:

You may notice that even something like this <iframe src='http://www.coolmath-games.com/0-fraction-splat/index.html'></iframe> results in the same. This is a technique called frame-busting. It's in their page's code:

<script>
<!-- Hide Script
 if (top.location != self.location) {
   top.location = self.location
 }
//End Hide Script-->
</script>

如果您有一台服务器,可以响应HTTP/1.1 204 No Content标头,则可以按照

If you have a server, that can respond with a HTTP/1.1 204 No Content header, you may be able to "deactivate" this frame buster as described here.

这篇关于更改iframe网址更改父窗口网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆