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.
这篇关于检查浏览器选项卡是否已经打开,所以我不会制作额外的选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:检查浏览器选项卡是否已经打开,所以我不会制


基础教程推荐
- 如何在特定日期之前获取消息? 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01