Thursday, June 14, 2007

How to add HTML dom elements dynamically inside a loaded page?

- solution:
- get the content of the loaded document in a tabbedbrowser
- alert(content.document); & alert(gBrowser.selectedBrowser.contentDocument); =>
[ Object XPCNativeWrapper [ object HTMLDocument ] ]
- rootBody = content.document.body; => <body> tag!
- then we can simply add a <div> tag by:
var tmpDiv = document.createElement('div');
rootBody.appendChild(tmpDiv);

- ref:
http://forums.mozillazine.org/viewtopic.php?t=522447&sid=47babc2b5e758ba21458bb73d733
http://developer.mozilla.org/en/docs/Extension_Code_Snippets:Tabbed_Browser#Getting_document_of_currently_selected_tab
http://developer.mozilla.org/en/docs/Working_with_windows_in_chrome_code#Content_windows

No comments: