使用window.open()函数打开已打开的选项卡,而不重新加载已打开的标签



我正在编写OnClick javascript代码来打开新的网页。

期望值:如果新页面尚未打开,我希望打开该页面,如果该页面已打开,则打开已存在的页面而不重新加载

我的代码:window.open(url,'dialers'(.focus((;

如果已经打开,此代码总是重新加载子页。请帮助实现我的要求。

您可以将窗口对象存储到一个变量中,并多次调用focus()方法,如下所示:

let newWindow = window.open(url,'dialers')
newWindow.focus()
doThing()
newWindow.focus()
doAnotherThing()
newWindow.focus()

HTML5引入了不应重新加载页面的history.pushState(page, caption, replace_url)。或者,如果你想在页面加载时进行修改,你可以这样做。

var currentURL = www.getitsol.com;
window.location.replace(currentURL + "?data=" + data.result, "_self");

最新更新