cfan
07-27-2006, 11:38 PM
Hello,
I'm trying to do something fairly straightforward: write a GreaseMonkey script that uses DOM to add a button to a page. Here's my code:
var elmReportButton = document.createElement('button');
elmReportButton.appendChild(document.createTextNode("Report"));
elmReportButton.onclick = function(){ alert("Hi!"); }
elmThreadURLButton.appendChild(elmReportButton);
Eventually I want to replace alert("Hi!"); with something more interesting, but let's use that as an example for now.
Unfortunately, this doesn't work. The JavaScript console just says "Component not defined" on the onclick line. (I've tried this with both function references and anonymous function declarations, and get the same result each time). What am I doing wrong?
Thanks!
I'm trying to do something fairly straightforward: write a GreaseMonkey script that uses DOM to add a button to a page. Here's my code:
var elmReportButton = document.createElement('button');
elmReportButton.appendChild(document.createTextNode("Report"));
elmReportButton.onclick = function(){ alert("Hi!"); }
elmThreadURLButton.appendChild(elmReportButton);
Eventually I want to replace alert("Hi!"); with something more interesting, but let's use that as an example for now.
Unfortunately, this doesn't work. The JavaScript console just says "Component not defined" on the onclick line. (I've tried this with both function references and anonymous function declarations, and get the same result each time). What am I doing wrong?
Thanks!