开发者

Firefox Extension, get a reference to the loaded document using browser.contentDocument

I want to write a simple firefox extension.

How can I get a reference to the loaded document object in a browser window? For example, how can I access the document in this html page loaded here on stackoverflow? According to the vague mozilla development center I can use browser.contentDocument, but it is not working for me.

    <?xml version="1.0"?>
<overlay id="sample" 
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/x-javascript">
 function change(){
  //var doc = document.getElementsByTagName("browser")[0].contentDocument;
  //var doc = document.browser.contentDocum开发者_运维知识库ent;
  var doc = browser.contentDocument;


  var body = doc.getElementsByTagName("body")[0];
  var text = doc.createTextNode("blah");
  body.appendChild(text);
 }
</script>
<statusbar id="status-bar">
  <statusbarpanel id="my-panel" label="click me" onclick="change();"  />
 </statusbar>
</overlay>


I'm not sure where you read that the variable is browser.contentDocument, since it's listed in several spots to be content.document (but I'm linking to the FAQ).


Variable for accessing content of current displayed document: window.content.document

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜