0

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

JavaScript コード:

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 のデバッグを手伝ってください。

4

1 に答える 1

0

iframeで生成されるコンテンツを制御できる場合は、次のようにすることができます。

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

またはより良いスクリプトバージョン

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

の中に

最高、マイケル

于 2012-04-27T15:06:45.617 に答える