跨域页面刷新

Nic*_*ick 5 html javascript php jquery

我正在尝试从子窗口刷新父窗口。在子窗口中使用以下代码,该代码驻留在 HTML 小部件中。

parent.parent.window.opener.location.reload()
Run Code Online (Sandbox Code Playgroud)

我没有在父页面中添加任何代码,因为它是一个 Moodle PHP 页面。如果两个窗口位于同一原点,则此代码可以正常工作。我不想跟去post-message()。因为我不想触及父窗口代码。你能帮我吗?只是为了刷新页面!!

Nic*_*ick 2

最后,我找到了一个解决方案来完成这项工作。

1) 您需要将以下代码放在父页面所在域的 HTML 文件中。 pageReload.html

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.3.js"></script>
<script type="text/javascript">
function reload() {
     parent.parent.window.opener.location.reload();
};
</script>
</head>
<body onload="reload()">
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

2) 在 HTML Widget 代码的子窗口中加载此 HTML 页面。添加以下代码行来加载上面的页面。

window.location = "http://www.yourparentdomain.com/pageReload.html";
Run Code Online (Sandbox Code Playgroud)

这样跨域页面刷新就可以了。