将使用iframe的某些网站重定向到另一个网址

时间:2014-05-20 10:05:32

标签: javascript iframe

我只是想知道这是否有效,我尝试使用以下脚本,如果它们不在域上,它确实可以重定向iframe,但是它不允许其他域,weeder和stumbleupon访问内容。

    window.onload = function(){
try
   {
     if (window.parent 
    && !(window.parent.location.hostname === "sitename.com" 
         || window.parent.location.hostname === "weeder.org"
         || window.parent.location.hostname === "stumbleupon.com"
         || window.parent.location.hostname === "localhost")){
          throw new Error();
       }
   }
   catch (e){
     window.location.href = "http://redirecttothis.com";
   }
}

如果我们试图阻止iframe滥用者,那将会很有效。

1 个答案:

答案 0 :(得分:0)

如果我理解正确,现代浏览器现在允许这样做。我认为你所寻找的是不可能的。

您可以查看以下网址

<iframe> javascript access parent DOM across domains?