检查浏览器选项卡是否已打开,这样我就不会制作额外的标签 [英] check if a browser tab is already open so I don't make extra tabs

查看:149
本文介绍了检查浏览器选项卡是否已打开,这样我就不会制作额外的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户将商品添加到我们的购物车时,它会在新标签页中打开我们的商店。奇怪的是不同的网站。

When a user adds an item to our shopping cart it opens our store in a new tab. Different websites oddly enough.

我想检查标签是否已经打开,然后用第二个项目重新填充它,而不是用更新的购物车打开另一个标签。

I would like to check if the tab is already open and then repopulate it it with the second item instead of opening another tab with the updated cart.

有没有办法用js检查?我想我可以跟踪我们打开了标签,但是我没有看到我如何确认它没有在向购物车添加商品之间的时间内关闭而没有做一些ajax请求ping两个页面等。这看起来有点过分。

Is there a way to check this with js? I imagine I can track that we opened the tab but I don't see how I can confirm that it wasn't closed in the time between adding items to the cart without doing some ajax requests pinging both pages etc. Which seems like overkill.

那么你如何检查浏览器标签是否已经打开?

So simply how do you check if a browser tab is already open?

使用解决方案编辑:
优先:

Edited with a solution: First:

var tab = window.open('http://google.com','MyTab');

然后:

if(tab) {
  var tab = window.open('http://yahoo.com','MyTab');
}


推荐答案

window.open 具有以下参数: var tab = window.open(url,name,specs,replace)
只要你使用相同的名称,该网址将被加载到该窗口/标签中。

window.open has the following parameters: var tab = window.open(url, name, specs, replace) As long as you use the same name the url will be loaded into that window/tab.

如果你想保留上面的描述符/引用( tab ),一旦用户刷新页面, window.open 返回该引用丢了。

If you wanted to keep the descriptor/reference (tab above), that window.open returns, once the user refreshes the page, that reference is lost.

这篇关于检查浏览器选项卡是否已打开,这样我就不会制作额外的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆