check if a browser tab is already open so I don#39;t make extra tabs(检查浏览器选项卡是否已经打开,所以我不会制作额外的选项卡)
问题描述
当用户将商品添加到我们的购物车时,它会在新标签页中打开我们的商店.奇怪的是不同的网站.
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.
这篇关于检查浏览器选项卡是否已经打开,所以我不会制作额外的选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:检查浏览器选项卡是否已经打开,所以我不会制


- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- 失败的 Canvas 360 jquery 插件 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- addEventListener 在 IE 11 中不起作用 2022-01-01
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01
- 400或500级别的HTTP响应 2022-01-01