[英]Reloading iframe and redirect parent issue
I'm on the same domain I need to go thru a login form by code and redirect to some page, the login does a bunch of settings across internal servers.我在同一个域中,我需要通过代码通过登录表单并重定向到某个页面,登录会在内部服务器上进行一系列设置。
I implemented a page with an iFrame我用 iFrame 实现了一个页面
<iframe id="iframe" src="<path to login page>" width="500" height="500"></iframe>
where I load the login page and populate the id/pwd and click the submit button by code and it works fine, the login after a few seconds comes with a logged in message在那里我加载登录页面并填充 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");
...
if in this browser I manually type the redirected page it works great all of the backend settings stick.如果在这个浏览器中我手动输入重定向的页面,它会很好地运行所有后端设置。 It works even on another browser tab.
它甚至适用于另一个浏览器选项卡。 But if I set the redirected location by code all of my login settings go away.
但是如果我通过代码设置重定向位置,我的所有登录设置都会消失。
window.location.href='<path of internal page>';
I tried placing a delay it didn't work我试过延迟它没有用
I tried wait until the iframe reloads but still it resets all of the login stuff when it redirects我尝试等到 iframe 重新加载,但它仍然会在重定向时重置所有登录内容
$("#iframe").on("load", function () {
window.location.href= ''<path of internal page>';
});
What could I be missing?????我会错过什么????
When you run script from code it will be executed withing the IFrame, but if you are running script from your console it will be executed directly in your main/parent page.当您从代码运行脚本时,它将与 IFrame 一起执行,但如果您从控制台运行脚本,它将直接在您的主/父页面中执行。
so, in your code you need to pass redirect command to your parent page using.因此,在您的代码中,您需要使用将重定向命令传递给您的父页面。
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.