Javascript 更改iframe url将更改父窗口url

Javascript 更改iframe url将更改父窗口url,javascript,iframe,Javascript,Iframe,我使用下面的页面在iframe中显示url的内容,并根据输入值进行更改 <html> <head> <script type="text/javascript"> function changeUrl() { var url=document.getElementById('browseurl').value; if(url!="") { if(url.indexOf("http")==-1) { url="http://"+url;

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

<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>

函数changeUrl()
{
var url=document.getElementById('browseurl').value;
如果(url!=“”)
{
if(url.indexOf(“http”)=-1)
{
url=“http://”+url;
}
document.getElementById('browserWnd')。src=url;
}
}
网址
我的问题是浏览在iframe中加载的url的一些内部页面会更改父窗口url而不是在iframe中加载

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

来自www.coolmath.com:

if (window.self != window.top) ...
这意味着该网站实际上没有被框住。

来自www.coolmath.com:

if (window.self != window.top) ...

这意味着该站点实际上没有被框住。

您可能会注意到,即使像这样的
也会导致相同的结果。这是一种技术,叫做。在他们页面的代码中:

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


如果您有一个服务器,它可以用
HTTP/1.1 204 No Content
头响应,那么您可以按照所述“停用”此frame buster。

您可能会注意到,即使是这样的
也会产生相同的结果。这是一种技术,叫做。在他们页面的代码中:

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


如果您有一台服务器,它可以用
HTTP/1.1 204 No Content
头响应,您可以按照说明“停用”此frame buster。

,但下面也可以在不使用self或top的情况下执行相同的操作@Paniyar您提供的链接确实有
self
top
。代码是:
if(top.location!=location)top.location.href=location.href但以下操作也会在没有self或top的情况下执行相同的操作@Paniyar您提供的链接确实有
self
top
。代码是:
if(top.location!=location)top.location.href=location.href我不能告诉你我搜索这个有多久了。另一个检查可能是
if(top!=self)
。我在查找一些旧代码,这些代码不断从我的
iframe
弹出页面,但不知道是什么导致了它。谢谢。我不能告诉你我找这个有多久了。另一个检查可能是
if(top!=self)
。我在查找一些旧代码,这些代码不断从我的
iframe
弹出页面,但不知道是什么导致了它。非常感谢。