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

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

问题描述

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

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)只要您使用相同的 name,url 就会被加载到该窗口/选项卡中.

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天全站免登陆