jQuery 从 iframe 内重新加载父窗口

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5351342/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 19:01:11  来源:igfitidea点击:

reload parent window from within an iframe

jqueryajaxiframe

提问by Dipesh KC

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

我在 iframe 中有我的登录页面,并希望在 iframe 中使用 ajax 和 jquery 重新加载父窗口而不刷新,但我收到了这样的错误

(this[0].ownerDocument || this[0]).createDocumentFragment is not a function
请帮忙!

回答by Dipesh KC

I could achieve this by reloading the page using javascript

我可以通过使用 javascript 重新加载页面来实现这一点

parent.location.reload();

then i fired a trigger to open the target iframe

然后我触发了一个触发器来打开目标 iframe

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

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

我需要这样的系统来应对特殊情况。这可能会帮助处于类似情况的其他人。

回答by Bert-Jan Wiegeraad

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.

后者强制完全重新加载,而第一个似乎更有效地更新,几乎就像 ajax。

回答by Ed Fryed

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

不要打扰!如果您使用 ajax,为什么要使用 iframe。

just load the login using

只需使用加载登录

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

$("您想在此处加载内容的位置").load("您的 iframe 的 src");

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

much simpler and alot more elegant.

更简单,更优雅。

回答by Marcos Silverio Rivera

You can use:

您可以使用:

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

Or:

或者:

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