javascript - Button is not added to the specific web page in mozilla extension -


i cannot figure out how add button, in mozilla extension.

function checkforvalidurl(tabid, changeinfo, tab) {     if(changeinfo.status == 'complete') {         var btn = document.createelement("button")         var t = document.createtextnode("click me");         btn.appendchild(t);         //appending dom          document.body.appendchild(btn);                document.body.insertbefore(button, document.body.firstchild);          alert("sucess");     } chrome.tabs.onupdated.addlistener(checkforvalidurl); 

i don't know .xul file

only content script has access page's dom. so, should move code there.

edit: remove listening of onupdate event , directly call function. content script run on every refresh.

function checkforvalidurl(tabid, changeinfo, tab) {         var btn = document.createelement("button")         var t = document.createtextnode("click me");         btn.appendchild(t);         //appending dom          document.body.appendchild(btn);         alert("suceeded"); } checkforvalidurl(); 

to position element use:

btn.setattribute("style", "position: absolute; top: 20px; left: 20px"); 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -