2011-05-03 82 views

回答

0

您可以使用window.parent.location来获取iframe中的父URL并相应地执行操作。如果未定义window.parent,则可能意味着直接调用了iframe.html。如果已定义,请检查该值并确保它来自您的域上的/index.html。

+0

@s imshaun,@Darin Dimitrov,'window.parent.location'只是将'iframe.html'重定向到'index.html',但我需要一些效果,比如'bing shopping' – 2011-05-03 21:48:41

+0

@yuli chika,'window.parent.location' doesn不会重定向到任何地方:它会为您提供父托管页面的位置(如果有)。如果您修改该值,则会重定向。但在这里我们正在讨论阅读它,并根据其价值作出相应的行动。顺便说一句,这是'iframe.html'知道父容器的唯一方法。 – 2011-05-03 21:50:52

0

我想这应该这样做...

var inIframe = window.location != window.parent.location; 
0

您可以在Iframe.html的使用此javascript:

if (top.location.href != 'http://www.site.com/index.html') { 
    // the proper redirect here 
    top.location.href = 'http://www.site.com/index.html'; 
} 

这种方式,将永远被载入为I帧

+0

Diallo,尽量使用你给的东西,但是当打开'index.html'时,实际上当你打开index.html的时候页面总会刷新 – 2011-05-03 21:36:58

+0

它不应该刷新,如果页面不同,条件只是'true' 。此代码进入iframe.html页面而不是index.html – Ibu 2011-05-03 22:02:12

2
if(self == top) 
location.href='/'; 

把这个在iframe页面

相关问题