javascript
  • html
  • firefox
  • firefox-addon
  • firefox-addon-sdk
  • 2014-09-10 70 views 0 likes 
    0

    您好我想創建一個Firefox擴展中的面板,其中的HTML代碼是由JavaScript代碼dinamically插入。這是代碼:Firefox擴展面板不執行HTML代碼

    var { ToggleButton } = require('sdk/ui/button/toggle'); 
    var panels = require("sdk/panel"); 
    var HTMLPage = '<html><head><link href="panel-style.css" type="text/css" rel="stylesheet"></head>' 
        + '<body><form>What is your name?: <input id="user-real-name" placeholder="Insert here your name"/><br />' 
        + '<input type="button" value="Submit" id="submit-btn"/></form><script src="get-text.js"></script>' 
        + '</body></html>'; 
    
    
    var button = ToggleButton({ 
        id: "button", 
        label: "tmp Button", 
        icon: { 
         "16": "./icon-16.png", 
         "32": "./icon-32.png", 
         "64": "./icon-64.png" 
        }, 
    onChange: handleChange 
    }); 
    var panel = panels.Panel({ 
        width: 200, 
        height: 100, 
        contentURL: "data:text/html," + HTMLPage, 
        onHide: handleHide 
    }); 
    function handleChange(state) { 
        if (state.checked) { 
         panel.show({ 
          position: button 
         }); 
        } 
    } 
    function handleHide() { 
        button.state('window', {checked: false}); 
    } 
    panel.on("show", function() { 
        panel.port.emit("show"); 
    }); 
    panel.port.on("text-entered", function (text) { 
        console.log(text); 
        panel.hide(); 
    }); 
    

    但HTML代碼沒有完全執行....面板是建立良好,但HTML代碼不會調用「GET-text.js」腳本。使用外部文件html和「contentURL:data.url(」panel.html「)」可以很好地對擴展進行編碼。你有任何解決方案?非常感謝。

    回答

    3

    我解決了.....問題解決在面板的代碼中插入該行:

    contentScriptFile: data.url("get-text.js"), 
    
    +0

    你可以(而且應該!)接受你自己的答案,如果這是你如何解決你的問題。 – Vache 2014-09-10 15:39:41

    +0

    我試着接受答案但我不能,因爲我必須等待2天 – hasmet 2014-09-10 15:54:18

    相關問題