简体   繁体   English

事件发生在同一选项卡中,同时在 Firefox 扩展中打开从活动选项卡到新选项卡的链接

[英]Event occurring in same tab, while opening a link from active tab to new tab in Firefox extension

var extension= {
check_domain : function(domain){
        //checking the domain name where event should occur........
},
on_load: function(e) {
    var doc_event = e.originalTarget;
extension.check_domain(doc_event.location.href);
},
init: function(e) {
if(gBrowser){
    gBrowser.addEventListener("DOMContentLoaded", this.on_load, false);
    }
} } window.addEventListener(  "load", function(e) { extension.init(); }, false);

The on_load function is called when new tab or link is clicked.单击新选项卡或链接时会调用 on_load function。 But my problem is that if we are opening new link from an active tab to a new tab, the event that is suppossed to be happening in the new tab happens in the active tab,while the new tab loads in the background.And if we are opening number of links like that all the events occur in the active tab not in the new tab.但我的问题是,如果我们打开从活动选项卡到新选项卡的新链接,则应该在新选项卡中发生的事件发生在活动选项卡中,而新选项卡在后台加载。如果我们正在打开的链接数量就像所有事件都发生在活动选项卡中而不是新选项卡中。

What i want is that the event should happen in the new tab even if it runs in the back ground.. How to identify a new tab and get the event to occur in new tab...(optional=>)Without making the new tab the active one.我想要的是事件应该在新标签中发生,即使它在后台运行。如何识别新标签并让事件在新标签中发生......(可选=>)不制作新标签选项卡活动的。

You didn't explain how you check in which tab the event happened, I suspect that you simply look at the currently active tab - and that won't work of course if something loaded in a background tab.您没有解释如何检查事件发生在哪个选项卡中,我怀疑您只是查看当前活动的选项卡 - 如果在后台选项卡中加载了某些内容,那当然不起作用。 You should instead look at e.target (the document that loaded) and check which tab it corresponds with:您应该查看e.target (加载的文档)并检查它对应的选项卡:

on_load: function(e) {
  var doc = e.target;
  var browser = gBrowser.getBrowserForDocument(doc);
  ...
},

This will give your the <browser> element of the tab where the document loaded (might also be null if the document loaded wasn't a top-level document).这将为您提供加载文档的选项卡的<browser>元素(如果加载的文档不是顶级文档,也可能是null )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM