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 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
.. 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").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.
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;
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.