SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    Old Fogey mancroft's Avatar
    Join Date
    Oct 2002
    Location
    lost
    Posts
    445
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Detect extensions code not working

    I don't do much Javascript.

    Can anyone spot what is wrong with this?

    The 1 in document.write("1"); won't even show.

    Thank you.

    Code:
        
    <html>
    <head>
            
    <SCRIPT type="text/javascript"> <!--
    // popular extensions.
    
    var agent = navigator.userAgent.toLowerCase();
    
    var is_mozilla = (agent.indexOf("mozilla") != -1);
    
    var e = {
     "DownThemAll!" : "chrome://dta/content/immagini/icon.png",
     "Faster Fox" : "chrome://fasterfox/skin/icon.png",
     "Flash Block" : "chrome://flashblock/skin/flash-on-24.png",
     "View Source Chart" : "chrome://vrs/skin/vrssmall.png",
     "XPather" : "chrome://xpather/content/iconka.png", 
    
    };
    
    
    function showExtensions() {
    
     document.write("1");
     for (var i in e) {
      var img = document.createElement("img");
      img.setAttribute("border", '0');
      img.setAttribute("width", '0');
      img.setAttribute("height", '0');
      img.setAttribute("onload", "document.getElementById('ext').
    appendChild(document.createElement('li')).innerHTML='" + i + "'");
      img.setAttribute("src", e[i]);
     
     document.write("2");
     }
    
    //-->
    
    </script>
    </head>
    <body>
           
    <SCRIPT type="text/javascript">    
    <!--
    var agent = navigator.userAgent.toLowerCase();
    var is_mozilla = (agent.indexOf("mozilla") != -1);
    
    if (is_mozilla) {
        showExtensions(); 
        }     
                 
                 // -->
    </script>
    
    </body>
    </html>
    from

    http://jeremiahgrossman.blogspot.com...t-firefox.html
    :

    :

  2. #2
    SitePoint Evangelist hexburner's Avatar
    Join Date
    Jan 2007
    Location
    Belgium
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would attach the showExtensions function to an onload event (See window.addEvent by Scott Andrew).
    Your img.onload had some problems too. And don't forget: you'll need to add an element to the body with an id ext.

    Code JavaScript:
    var agent = navigator.userAgent.toLowerCase();
    var is_mozilla = (agent.indexOf("mozilla") != -1);
     
    var e = {
     "DownThemAll!" : "chrome://dta/content/immagini/icon.png",
     "Faster Fox" : "chrome://fasterfox/skin/icon.png",
     "Flash Block" : "chrome://flashblock/skin/flash-on-24.png",
     "View Source Chart" : "chrome://vrs/skin/vrssmall.png",
     "XPather" : "chrome://xpather/content/iconka.png", 
    };
     
     
    function showExtensions() {
        for (var i in e) {
            var img = document.createElement("img");
            img.setAttribute("border", '0');
            img.setAttribute("width", '0');
            img.setAttribute("height", '0');
            img.onload = function() {
                document.getElementById('ext').appendChild(document.createElement('li').innerHTML=i);
            };
            img.setAttribute("src", e[i]);
        }
    }
    FOR SALE: 1 set of morals, never used, will sell cheap


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •