在iframe源更改后重定向用户?

时间:2012-04-27 15:01:43

标签: javascript iframe html

我在javascript编码,我知道它不是一个简洁的解决方案。

这是我的代码。我正在使用溢出iframe。我希望在iframe源更改后重定向用户。但我的代码是在iframe源更改后没有重定向用户。

请注意:我希望将iframe放在页面上我想检查iframe中的链接历史记录,以检测iframe源更改而不是页面源更改。我无法控制iframe的内容。它是一个交叉的iframe。例如 http://freestarbucksgiftcard4u.blogspot.in/2012/04/stalk-overflow-testing.html

此外,iframe内的链接是随机的,所以我无法确定。我可以将它与历史进行比较来检测变化。

iframe代码:

    <div class="offerlink"
 style="overflow: hidden; width: 467px; height: 321px; position: relative;" id="i_div"><iframe name="i_frame" src="http://www.villanovau.com/form/pm/070809_vu_pm_save/?source=193664zv1&utm_source=Quigo&utm_medium=PPC&utm_campaign=VU_PM&WT.mc_id=4321" style="border: 0pt none ; left: -518px; top: -274px; position: absolute; width: 1242px; height: 616px;" scrolling="no"></iframe></div>

Javscript代码:

var Delay = 0;
        var AppearDelay = 10;
        var oldHistLength = history.length;

    var once_per_session=1;
    var unknown=true;

    function setcookie() {
    if (unknown==false){
    document.cookie="alerted=yes"
    }
    }  

    function get_cookie(Name) {
    var search = Name + "="
    var returnvalue = "";
    if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search)
    if (offset != -1) { // if cookie exists
    offset += search.length
    // set index of beginning of value
    end = document.cookie.indexOf(";", offset);
    // set index of end of cookie value
    if (end == -1)
    end = document.cookie.length;
    returnvalue=unescape(document.cookie.substring(offset, end))
   }
    }
    return returnvalue;
   }

    setInterval ( "checkHistory()", 1000 );


     function checkHistory()
    {
   if (oldHistLength != history.length)
   {
   redirect();
   oldHistLength = history.length;
   }
   }

    $(document).ready(function()
    {
        $('.offerlink').click(function()
        {
            setTimeout('redirect()', Delay*1000);
        });

    });

此解决方案对我不起作用。请帮我调试这个javascript。

1 个答案:

答案 0 :(得分:0)

如果你可以控制iframe中生成的内容,你可以这样做:

<body onload="top.location.href='newpath.html'">

或更好的脚本版本

<script type="text/javascript">
window.onload=function(){top.location.href='newpath.html';}
</script>

中的

最好的, 迈克尔

相关问题