English 中文(简体)
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.contentDocument;
  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





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

jQuery block moving

I wanna move a div block to the top, so I coded like this: CSS part: .movingPart{ margin-top:80px; } jQuery part: $(document).ready(function() { $( #btn ).click(function() { $( .movingPart )....

Private FireFox plugin

I m looking at getting a FireFox plugin developed - but is it possible to create a plugin that is for private use only, so only those I share it with have it and not open to the masses? Need this for ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Cross-browser development

I m developing a web application for a new service, starting from Firefox 3.5. The interface design is tableless, only using divs + CSS & performance-blessed practices. Now, while being ...

Cross browser way of setting IFrame to "about:blank"?

Does anybody know a proper, cross-browser way to "empty" an IFrame? Is "about:blank" recognized without error across all browsers? Is it valid to give an IFrame an empty src?

热门标签