短暂等待后强制重新加载 html 页面

发布于 2024-07-10 20:47:16 字数 317 浏览 7 评论 0原文

我有一个 html 页面 A 和页面中的一个链接,该链接在新窗口中打开页面 B。 如何在单击并打开此链接时重新加载页面 A?

编辑:

我应该更清楚。 页面 B 在新窗口中打开,而不是作为弹出窗口打开。 相关超链接的目标属性设置为 _blank。 从我得到的答案中得到线索(谢谢大家!),我尝试设置 onclick = "window.location.reload()" 并且它工作得很好。

但是我有一个问题。 事实上,这完全是另一个问题。 如何确保页面A的重新加载等待在新窗口中打开的页面(页面B)加载?

I have a html page A and a link in the page which opens up page B in a new window. How to reload the page A on clicking and opening this link ?

EDIT:

I should have been more clear. Page B opens in a new window and not as a popup. The hyperlink in question has its target attribute set to _blank. Taking a clue from the answers that I got (Thanks guys !), I tried setting onclick = "window.location.reload()" and it works perfectly fine.

However I have a problem. In fact another question altogether. How to make sure that the reload of page A waits until the page opened in the new window (page B) loads ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

哭泣的笑容 2024-07-17 20:47:16

像这样的东西:

<a href="javascript:window.open('pageB.htm');window.location.reload();">open page b</a>

Something like this:

<a href="javascript:window.open('pageB.htm');window.location.reload();">open page b</a>
把人绕傻吧 2024-07-17 20:47:16

最简单的方法是,

<a href="# " onClick="window.open('newPage.htm','window','width=400,height=200')">link</a>

如果我没记错的话,应该打开窗口,然后由于返回未被抑制,因此将重新加载页面。

The simplest way would be to do

<a href="# " onClick="window.open('newPage.htm','window','width=400,height=200')">link</a>

If I remember correctly that should open the window and then since the return has not been suppresed will reload load the page.

巷雨优美回忆 2024-07-17 20:47:16

根据您的措辞,我不确定这是否是您想要的,但是如果您想从弹出窗口中的链接重新加载打开的窗口,请尝试

self.opener.location.href = self.opener.location.href;

编辑,根据您的新评论,只需在正文加载中使用上面的代码新窗户

<body onload="self.opener.location.href = self.opener.location.href;">

I am not exactly sure if this is what you want based on your wording, but if you want to reload the opening window from a link in the popup try

self.opener.location.href = self.opener.location.href;

Edit, based on your new comments just use the code above in the body onload of the new window

<body onload="self.opener.location.href = self.opener.location.href;">
如梦 2024-07-17 20:47:16

您可以使用 setTimeout() 来延迟重新加载。

You can use setTimeout() to delay the reload.

锦爱 2024-07-17 20:47:16

尝试这个:

<script type="text/javascript">
function openPage(elem) {
    function reloadCurrentPage() {
        location.reload();
    }

    var page = window.open(elem.href, '_blank');
    page.onload = function() {
        reloadCurrentPage();
    }

    if (/MSIE/.test(navigator.userAgent)) { // fix for IE
        var timer = setInterval(function() {
            if (page.document.readyState == 'complete') {
                clearInterval(timer);
                reloadCurrentPage();
            }
        }, 100);
    }
}
</script>

<p><a href="second.html" onclick="openPage(this); return false;">second.html</a></p>

Try this:

<script type="text/javascript">
function openPage(elem) {
    function reloadCurrentPage() {
        location.reload();
    }

    var page = window.open(elem.href, '_blank');
    page.onload = function() {
        reloadCurrentPage();
    }

    if (/MSIE/.test(navigator.userAgent)) { // fix for IE
        var timer = setInterval(function() {
            if (page.document.readyState == 'complete') {
                clearInterval(timer);
                reloadCurrentPage();
            }
        }, 100);
    }
}
</script>

<p><a href="second.html" onclick="openPage(this); return false;">second.html</a></p>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文