簡體   English   中英

重新加載 iframe 和重定向父問題

[英]Reloading iframe and redirect parent issue

我在同一個域中,我需要通過代碼通過登錄表單並重定向到某個頁面,登錄會在內部服務器上進行一系列設置。

我用 iFrame 實現了一個頁面

  <iframe id="iframe" src="<path to login page>" width="500" height="500"></iframe>

在那里我加載登錄頁面並填充 id/pwd 並通過代碼單擊提交按鈕,它工作正常,幾秒鍾后登錄帶有登錄消息

  .. args have the data pulled from DB
    var $myIFrame = $('#iframe');
    $myIFrame.contents().find("input#userID").val(arg1);
    $myIFrame.contents().find("input#userPwd").val(arg2);

    $myIFrame.contents().find("input#mybutton").trigger("click");           
   ...  

如果在這個瀏覽器中我手動輸入重定向的頁面,它會很好地運行所有后端設置。 它甚至適用於另一個瀏覽器選項卡。 但是如果我通過代碼設置重定向位置,我的所有登錄設置都會消失。

window.location.href='<path of internal page>';

我試過延遲它沒有用

我嘗試等到 iframe 重新加載,但它仍然會在重定向時重置所有登錄內容

$("#iframe").on("load", function () {
    window.location.href= ''<path of internal page>';
    });

我會錯過什么????

當您從代碼運行腳本時,它將與 IFrame 一起執行,但如果您從控制台運行腳本,它將直接在您的主/父頁面中執行。

因此,在您的代碼中,您需要使用將重定向命令傳遞給您的父頁面。

window.top.location = '<path of internal page>';
var page_url = '<path of internal page>';
document.getElementById('your_iframe_id').onload = function() { 
    if(jQuery("#your_iframe_id").contents().find("body").hasClass('logged-in'))
    {                   
        window.location.href = page_url;
    }                                                   
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM