繁体   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