ddrwin
火狐狸
火狐狸
  • UID31229
  • 注册日期2009-11-28
  • 最后登录2020-02-29
  • 发帖数113
  • 经验20枚
  • 威望0点
  • 贡献值6点
  • 好评度1点
阅读:3017回复:2

请教GA?扩展切换tab后显示不正常的问题

楼主#
更多 发布于:2011-03-07 10:11
GA?是在状态栏显示网页是否安装google流量统计的小扩展:
https://g.mozest.com/thread-37496-1-1


在ff4.0b12下,包含google流量统计的网页可以正常显示GA?状态,但切换到别的tab再切换回来以后,这个网页就复位成灰色图片了。

在ff3.x版本里,切换tab是可以保留彩色图片的状态的。我猜想是不是ff4.0改了系统函数所致?请懂代码的师傅帮忙看看能否修复这里面的bug吧。谢谢了!

这是GA?监测网页代码里是否包含google流量统计代码的源码,第46行有onTabsChanged: function(aEvent)的函数:

window.addEventListener("load", function() { myExtensionGA.init(); }, false);

    var myExtensionGA = {
      init: function() {
        var appcontent = document.getElementById("appcontent");   // browser
        if(appcontent)
          appcontent.addEventListener("load", this.onPageLoad, true);
          appcontent.addEventListener("TabSelect", this.onTabsChanged, true);
      },

      onPageLoad: function(aEvent) {

      
              // look in document
              var icon = document.getElementById('gainstalled-status');
        var doc = aEvent.originalTarget; // doc is document that triggered "onload" event
        // do something with the loaded page.
        // doc.location is a Location object (see below for a link).
        // You can use it to make your code executed on certain pages only.
        //if(doc.location.href.search("forum") > -1)
         // alert("a forum page is loaded");

         if(doc.body) {

         var samplePanel = document.getElementById('gainstalled-status');
         
                      
         if(doc.documentElement.innerHTML.search("urchinTracker") > -1) {
          //alert("gA is loaded");
          icon.setAttribute("status", "success");
          samplePanel.tooltipText = "Google Analytics is installed on this page."
         } else if (doc.documentElement.innerHTML.search("google-analytics.com/ga.js") > -1) {
          //alert("gA is loaded");
          icon.setAttribute("status", "success");
          samplePanel.tooltipText = "Google Analytics is installed on this page."
         } else {
          icon.setAttribute("status", "testfailed");
          samplePanel.tooltipText = "Google Analytics is NOT installed on this page."
         }

         }
         
      },


    onTabsChanged: function(aEvent)
      {

    //alert("tab change");

    // look in document
              var icon = document.getElementById('gainstalled-status');
        var doc = gBrowser.selectedBrowser.contentDocument; // doc is document that triggered "onload" event
        // do something with the loaded page.
        // doc.location is a Location object (see below for a link).
        // You can use it to make your code executed on certain pages only.
        //if(doc.location.href.search("forum") > -1)
         // alert("a forum page is loaded");

         if(doc.body) {

         var samplePanel = document.getElementById('gainstalled-status');
         
                      
         if(doc.documentElement.innerHTML.search("urchinTracker") > -1) {
          //alert("gA is loaded");
          icon.setAttribute("status", "success");
          samplePanel.tooltipText = "Google Analytics is installed on this page."
          } else if (doc.documentElement.innerHTML.search("google-analytics.com/ga.js") > -1) {
          //alert("gA is loaded");
          icon.setAttribute("status", "success");
          samplePanel.tooltipText = "Google Analytics is installed on this page."
         } else {
          icon.setAttribute("status", "testfailed");
          samplePanel.tooltipText = "Google Analytics is NOT installed on this page."
         }

         }
         

       
      }
    }


隔壁的slimx大大回复说:The TabClose, TabSelect, and TabOpen events no longer bubble up to the tabbrowser element (gBrowser). Event listeners for those events should be added to gBrowser.tabContainer rather than to gBrowser directly.

我不懂如何替换gBrowser.tabContainer,有高人帮忙指点一下吗?
问几个问题,关于reload缓存、重新载入扩展、图片/js/帧超时能否跳过...
https://www.firefox.net.cn/forum/viewtop ... 145#274145

如何高亮编辑框里的文字的问题?
https://www.firefox.net.cn/forum/viewtop ... ht=#272852

请教GA?扩展切换tab后显示不正常的问题
https://www.firefox.net.cn/forum/viewtopic.php?t=35480
GOLF-AT
千年狐狸
千年狐狸
  • UID11611
  • 注册日期2006-02-20
  • 最后登录2019-12-30
  • 发帖数3239
  • 经验265枚
  • 威望1点
  • 贡献值260点
  • 好评度59点
  • 社区居民
  • 忠实会员
1楼#
发布于:2011-03-07 10:11
最新的 Firefox 4.0b13pre 测试:
1) window.addEventListener("load", function() { myExtensionGA.init(); }, false);  无效,居然要
    document.addEventListener('load', function() { myExtensionGA.init() }, true);
    这个应该是 4.0 的 bug

2) init: function() 改成:
init : function() {
        try {
             var container = gBrowser.tabContainer;
            container.addEventListener("load", this.onPageLoad, true);
            container.addEventListener("TabSelect", this.onTabsChanged, true);
        }catch(e) {}
    },
ddrwin
火狐狸
火狐狸
  • UID31229
  • 注册日期2009-11-28
  • 最后登录2020-02-29
  • 发帖数113
  • 经验20枚
  • 威望0点
  • 贡献值6点
  • 好评度1点
2楼#
发布于:2011-03-07 10:11
GOLF-AT:最新的 Firefox 4.0b13pre 测试:
1) window.addEventListener("load", function() { myExtensionGA.init(); }, false);  无效,居然要
    document.addEventListener('load', function() { myExtensionGA.init() }, true);
    这个应该是 4.0 的 bug

2) init: function() 改成:
init : function() {
        try {
             var container = gBrowser.tabContainer;
            container.addEventListener("load", this.onPageLoad, true);
            container.addEventListener("TabSelect", this.onTabsChanged, true);
        }catch(e) {}
    },
回到原帖



亲爱的GOFT哒哒,我按你的代码改了,在第一次打开tab的时候,没有显示图标,从其他tab切换到当前tab以后,就正常显示图标了,而且再切换tab都不会丢失图标了!非常好,赞一下你的代码!

所以我把之前和你的代码合二为一就可以在第一次打开tab显示图标,切换tab以后也不会丢失图标状态了。非常感谢你啊!我是在rc1下测试的。

init : function() {
        try {
             var container = gBrowser.tabContainer;
            container.addEventListener("load", this.onPageLoad, true);
            container.addEventListener("TabSelect", this.onTabsChanged, true);
			}catch(e) {}

		    var appcontent = document.getElementById("appcontent");   // browser
			if(appcontent)
			appcontent.addEventListener("load", this.onPageLoad, true);
			appcontent.addEventListener("TabSelect", this.onTabsChanged, true);
    },
就好了。


另外,你说
window.addEventListener("load", function() { myExtensionGA.init(); }, false);
无效是啥意思?改不改成
document.addEventListener('load', function() { myExtensionGA.init() }, true);
好像没变化?
问几个问题,关于reload缓存、重新载入扩展、图片/js/帧超时能否跳过...
https://www.firefox.net.cn/forum/viewtop ... 145#274145

如何高亮编辑框里的文字的问题?
https://www.firefox.net.cn/forum/viewtop ... ht=#272852

请教GA?扩展切换tab后显示不正常的问题
https://www.firefox.net.cn/forum/viewtopic.php?t=35480
游客

返回顶部