开发者

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. 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 l开发者_Go百科oads 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:

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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜