簡體   English   中英

Firebug Lite 可以有條件地加載嗎?

[英]Can Firebug Lite be loaded conditionally?

我希望能夠有條件地加載 Firebug lite(例如,基於調試變量的值)。 我試過這個:

<script type="text/javascript">

    var fileref; 

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

</script>

在我的<head>頂部,但無濟於事。 有人有什么建議嗎?

創建元素后,您需要將其插入到 DOM 中。 這可以使用.appendChild()來完成。

將此添加到您的if

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

您可以將其添加到您的頁腳。 我願意接受批評。 如果你能做得更好,go 就可以了。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM