如何实现何时复制浏览器选项卡 [英] How to realize when a browser tab has been duplicated
问题描述
我在Chrome(工作阶段的东西)上有一个重复的标签时遇到问题,我想避免重复标签的操作(或缺少关闭重复标签的操作).我正在打开选项卡,因为它是一个弹出窗口,没有地址栏,没有状态栏,也没有任何东西,只有窗口.在IE和Firefox中无法复制选项卡(作为弹出窗口打开)(至少我没有找到一个选项卡),但是在chrome中仍然可以.
I'm having problems with a duplicate tab on Chrome (session's stuff) and I'd like to avoid the action of duplicating tabs (or lacking that close the duplicate one). I'm opening the tab as it was a popup, with no address bar, no status bar, and no nothing, just the window. There's no way to duplicate a tab (opened as a popup) in IE and Firefox (at least I havent found one), but in chrome is still possible.
Any idea how to approach this?
谢谢!
推荐答案
目标
只需澄清一下:目标是检测(并关闭)通过Chrome的复制"右键菜单选项打开的选项卡.
Just to clarify: The goal is to is to detect (and close) a tab that has been opened via Chrome's "Duplicate" right-click menu option.
第一次尝试
复制选项卡"操作的工作原理几乎与用户在单击返回"然后单击转发"后重新加载页面时完全相同,因此您基本上实现的是
The "Duplicate tab" action works almost exactly like when reloading a page after the user has clicked "Back" then "Forward", so you are basically implementing a version of this question:
function onLoad()
{
if ($('#myStateInput').val() === '') // Load with no state.
$('#myStateInput').val('already loaded'); // Set state
else
alert("Loaded with state. (Duplicate tab or Back + Forward)");
}
那太好了,但您 only 只想检测何时复制标签".为此,我们可以清除onbeforeunload
中的状态.之所以有效,是因为onbeforeunload
仅在用户单击上一步"或前进"时才被调用,而在复制选项卡时不会被调用.
Thats great and all, but you only want to detect when you "Duplicate tab". To do this we can blank out the state in onbeforeunload
. This works because onbeforeunload
gets only called when the user clicks "Back" or "Forward" but not when duplicating a tab.
第二次尝试
function onLoad()
{
if ($('#myStateInput').val() === '') // Load with no state.
$('#myStateInput').val('already loaded'); // Set state
else
alert("Duplicate tab! Do something.");
$(window).on('beforeunload', function() // Back or Forward buttons
{
$('#myStateInput').val(''); // Blank the state out.
});
}
这篇关于如何实现何时复制浏览器选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!