开发者

Can Firebug Lite be loaded conditionally?

I'd like to be able to load Firebug lite conditionally (eg, based on the value of debug variable). I've tried this:

<script type="text/javascript">

    var fi开发者_如何学编程leref; 

    if(condition) {
        fileref=document.createElement('script')
        fileref.setAttribute("type","text/javascript")
        fileref.setAttribute("src", "https://getfirebug.com/firebug-lite.js")
    }

</script>

at the top of my <head>, but to no avail. Anyone have any suggestions?


After creating an element, you need to insert it into the DOM. This can be done using .appendChild().

Add this to your if:

var head = document.getElementsByTagName("head")[0]; 
head.appendChild(fileref);


You could add this to your footer. I'm open to criticism. If you can make this better, go for it.

<script>

        // First uncomment this to get your user agent, 
        // So we can hide Firebug Lite from the general public
        // Remember to change this if you change browsers :-)
        // document.write("<p>User agent: "+ navigator.userAgent +"</p>");

        // Note: Not sure why but Firebug Lite may open in a new tab, even if you tell it not to 
        // UNLESS you use Google Chrome for Android (NOT the Beta version!) 

        if (
            navigator.userAgent == "Mozilla/5.0 (Linux; Android 4.4.2;"
        ) 
        {    
            var fileref; 
            fileref=document.createElement("script");
            fileref.setAttribute("type","text/javascript");

            // Pick your version here https://getfirebug.com/firebuglite
            fileref.setAttribute("src", "http://fbug.googlecode.com/svn/lite/branches/firebug1.4/content/firebug-lite-dev.js");

            // Add to DOM
            var head = document.getElementsByTagName("head")[0]; 
            head.appendChild(fileref);
        }

        /* Defaults (supposedly)
        saveCookies - false
        startOpened - false
        startInNewWindow - false
        showIconWhenHidden - true
        overrideConsole - true
        ignoreFirebugElements - true
        disableXHRListener - false
        disableWhenFirebugActive - true
        enableTrace - false
        enablePersistent - false
        */

    </script>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜