Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/467.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何知道用户单击“新建选项卡”按钮是否打开了新选项卡?_Javascript_Firefox Addon Webextensions - Fatal编程技术网

Javascript 如何知道用户单击“新建选项卡”按钮是否打开了新选项卡?

Javascript 如何知道用户单击“新建选项卡”按钮是否打开了新选项卡?,javascript,firefox-addon-webextensions,Javascript,Firefox Addon Webextensions,在FirefoxWebExtensions中,如何知道新选项卡是以何种方式打开的 按用户单击“新建”选项卡按钮(+) 按用户单击链接,如? 注意:我不在乎是否通过window.open() 我发现,在chrome.tabs.Tab.onCreated的回调中,传入了一个参数,假设它名为firefoxTab: 对于通过单击+打开的选项卡,其URL为about:newtab 对于通过单击打开的选项卡,其URL为about:blank 但是有一个例外,如果Firefox启动后的第二个选项卡通

在FirefoxWebExtensions中,如何知道新选项卡是以何种方式打开的

  • 按用户单击“新建”选项卡按钮(+)
  • 按用户单击链接,如
    ? 注意:我不在乎是否通过
    window.open()

我发现,在
chrome.tabs.Tab.onCreated
的回调中,传入了一个参数,假设它名为
firefoxTab

  • 对于通过单击+打开的选项卡,其URL为
    about:newtab
  • 对于通过单击
    打开的选项卡,其URL为
    about:blank
但是有一个例外,如果Firefox启动后的第二个选项卡通过点击“+”打开,其URL将是
about:blank
,而不是
about:newtab
。我认为这是Firefox的缺陷,在Bugzilla上发布了一个bug


同时,还有其他方法可以做到这一点吗?

我可以确认Firefox 52.0中也有这种情况(在夜间测试时,Firefox 55.0a1产生了类似的结果)

重新启动后第一次单击
+
时发生的事件有:

tabs.onUpdated->arg[0]=1::arg[1]=Object{status:“正在加载”}::arg[2]=Object{id:1,索引:1,windowId:1,selected:false,highlighted:false,active:false,pinted:false,status:“完成”,incognito:false,宽度:1098,高度:812,声音:false,mutedInfo:{muted:false},cookieStoreId:“默认”,url:“关于:空白”,标题:“新建选项卡”}
tabs.onActivated->arg[0]=对象{tabId:1,windowId:1}
tabs.onHighlighted->arg[0]=对象{tabid:Array[1],windowId:1}
tabs.onCreated->arg[0]=Object{id:1,index:1,windowId:1,selected:true,highlighted:true,active:true,pinted:false,status:“complete”,incognito:false,width:1098,height:812,audible:false,mutedInfo:{muted:false},cookieStoreId:“firefox default”,url:“about:blank”,title:“New Tab”}
tabs.onUpdated->arg[0]=1::arg[1]=Object{status:“loading”,url:“about:newtab”}::arg[2]=Object{id:1,index:1,windowId:1,selected:true,highlighted:true,active:true,pinted:false,status:“complete”,incognito:false,宽度:1098,高度:812,声音:false,mutedInfo:{muted:false},cookieStoreId:“firefox默认”,url:“关于:新标签”,标题:“新标签”}
webNavigation.onBeforeNavigate->arg[0]=对象{url:“关于:新标签”,时间戳:1489473167445,框架ID:0,父框架ID:-1,选项卡ID:1}
webNavigation.onCommitted->arg[0]=对象{url:“关于:newtab”,时间戳:1489473167466,frameId:0,parentFrameId:-1,tabId:1,transitionType:“link”,transitionQualifiers:Array[0]}
webNavigation.onDOMContentLoaded->arg[0]=对象{url:“关于:新标签”,时间戳:1489473167718,框架ID:0,父框架ID:-1,选项卡ID:1}
tabs.onUpdated->arg[0]=1::arg[1]=Object{status:“complete”}::arg[2]=Object{id:1,index:1,windowId:1,selected:true,highted:true,active:true,pinted:false,status:“complete”,incognito:false,width:1098,height:812,auble:false,mutedInfo:{muted:false},cookieStoreId:“firefox default”,url:“关于:新选项卡”,标题:“新选项卡”}
webNavigation.onCompleted->arg[0]=对象{url:“关于:newtab”,时间戳:1489473167914,帧ID:0,父帧ID:-1,选项卡ID:1}
tabs.onUpdated->arg[0]=1::arg[1]=Object{status:undefined}::arg[2]=Object{id:1,index:1,windowId:1,selected:true,highted:true,active:true,pinted:false,status:“complete”,incognito:false,width:1098,height:812,auble:false,mutedInfo:{muted:false},cookieStoreId:“firefox默认”,url:“关于:新选项卡”,标题:“新选项卡”}
第二次单击
+
时发生的事件有(是,事件明显减少,没有
webNavigation
事件):

tabs.onActivated->arg[0]=对象{tabId:2,windowId:1}
tabs.onHighlighted->arg[0]=对象{tabid:Array[1],windowId:1}
tabs.onCreated->arg[0]=Object{id:2,index:2,windowId:1,selected:true,highlighted:true,active:true,pinted:false,status:“complete”,incognito:false,width:1098,height:812,audible:false,muted:false},cookieStoreId:“firefox default”,url:“about:newtab”,title:“New Tab”}
随后单击
+
会导致类似事件。有时会触发其他事件。此外,根据
about:newtab
页面的内容,还会触发更多事件

相反,单击
时会发生许多其他事件。只有
选项卡。一次创建的
事件是:

tabs.onCreated->arg[0]=Object{id:3,index:2,windowId:1,selected:true,highlighted:true,active:true,pinted:false,status:“loading”,incognito:false,width:1098,height:812,audible:false,muted:false},cookieStoreId:“firefox default”,url:“about:blank”,title:“Connecting…”
如果您想区分,可以查看
选项卡中提供的
标题
url
。一旦创建了
事件。对于链接,您有:

url:“关于:空白”,标题:“连接…”
要单击
+
,您有以下两种选择之一:

url:“关于:空白”,标题:“新建选项卡”//First`+`
url:“关于:新标签”,标题:“新标签”//`+`

请更具体一点:
在单击时不会打开选项卡。你是指类似于
的内容吗?@Makyen是的,感谢澄清。非常有用,我没有检查
标题
属性。如果用户以本机语言安装Firefox,则会出现新问题