reload parent window from within an iframe

2020-01-29 08:18发布

问题:

I have my login page in an iframe and wished to reload the parent window using ajax and jquery from within iframe without refreshing but i'm getting errors like this

(this[0].ownerDocument || this[0]).createDocumentFragment is not a function
please help!

回答1:

I could achieve this by reloading the page using javascript

parent.location.reload();

then i fired a trigger to open the target iframe

$("#log-inout").trigger("click");

I needed such system for a peculiar condition. This might help others in similar conditions.



回答2:

parent.location.href=parent.location.href

gives a smoother result than

parent.location.reload()

the latter forces a complete reload while the first seems to update more effectively almost like ajax.



回答3:

dont bother! why use iframes at all if you are using ajax.

just load the login using

$("where you want to load the content here").load("src of your iframe here");

//load via ajax
$("div").load("login.php");

much simpler and alot more elegant.



回答4:

You can use:

window.parent.location.href = "Create?Param=value";

Or:

window.parent.location.href = "http://www.stackoverflow.com";