从JS中的iframe重新加载页面
我有一个iframe,我想通过它刷新主页。我尝试了诸如window.location.reload()
等的函数。但是看来它不起作用。 我需要将重新加载函数放在不在主页上的iframe上。 我可以得到document.referrer
获得主页。
iframe codesandbox 请参阅此
<div class="iframe-container">
<iframe class="iframe-layout" src="https://zqdqmn.csb.app/"></iframe>
</div>
/ strong > iframe part
<script>
function redirectToGoogle() {
const mainUrl = document?.referrer
window.location.href = `${mainUrl}`
// window.open(mainUrl,"_self")
}
</script>
</body>
I have an iframe and I want to refresh the main page through it. I've tried functions such as window.location.reload()
etc.. but it seems it doesn't work.
I need to put the reload function on the iframe not on the main page.
I could get as much as document.referrer
to get the main page.
Iframe codesandbox
SEE THIS
Main page codesandbox SEE THIS
<div class="iframe-container">
<iframe class="iframe-layout" src="https://zqdqmn.csb.app/"></iframe>
</div>
Iframe Part
<script>
function redirectToGoogle() {
const mainUrl = document?.referrer
window.location.href = `${mainUrl}`
// window.open(mainUrl,"_self")
}
</script>
</body>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要与横断面互动,使我们成为
窗口。 postmessage
和使用onMessage
或addeventListener(“消息”,...)
。codesandbox上的示例使用特定的来源,而此处的示例显示了如何处理它,如果目标和/或源窗口具有
'null'
作为Origin。To interact with cross origin pages make us of
window.postMessage
and MessageEvents usingonmessage
oraddEventListener("message", ...)
.The example on codesandbox shows how to make use with a specific origin, while this example here shows, how to handle it, if the target and/or source window have
'null'
as origin.