Jump to content

is there such thing as iframe.innerHTML???


jnroche

Recommended Posts

I used iframe for rich-text editing, for my forums site. If the user wants to create a new post, i want to simply capture whatever the user writes within the iframe object and be able to save it to the database.there was no problem with getting the iframe to work or to make it editable. the problem starts when i want to capture whatever the value is written to it????help needed :)

Link to comment
Share on other sites

use document.frames["iframeName"].document.body.innerHTML to get the contents of the iframe.
i tried it but i get (in mozilla browser) document.frames has no properties. this is a sample code relevant to the issue:<iframe id="iframeidx" name="iframeid"></iframe> <form> <input type="text" id="word"/><a onMouseDown="testframe()">Submit</a> <input type="button" value="iframe" onClick="document.getElementById('iframeidx').contentDocument.designMode='On'" > <input type="button" value="alert" onClick="testframe()" > </form>anything wrong??? :)
Link to comment
Share on other sites

@aspnetguy - Would this also work?
var iframe = document.getElementById("theIFrameID");var code = iframe.document.body.innerHTML;

You would think it would but strangley it doesn't it returns the current document.body.innerHTML not the document in the iframe, so what you get back is the same as doing document.body.innerHTML. With the name property depreciated in XHTML you would think this method would work and be preferred.
Link to comment
Share on other sites

You would think it would but strangley it doesn't it returns the current document.body.innerHTML not the document in the iframe, so what you get back is the same as doing document.body.innerHTML. With the name property depreciated in XHTML you would think this method would work and be preferred.
AAAHH IE!I just found this, it might help:
Mozilla supports the W3C standard of accessing iframe's document object through IFrameElm.contentDocument, while Internet Explorer requires you to access it through document.frames["name"] and then access the resulting document:
  function getIFrameDocument(aID){  var rv = null;  // if contentDocument exists, W3C compliant (Mozilla)  if (document.getElementById(aID).contentDocument){    rv = document.getElementById(aID).contentDocument;  } else {    // IE    rv = document.frames[aID].document;  }  return rv;   }

http://www-128.ibm.com/developerworks/web/...ry/wa-ie2mozgd/
Link to comment
Share on other sites

AAAHH IE!I just found this, it might help:http://www-128.ibm.com/developerworks/web/...ry/wa-ie2mozgd/
thanks so much for all your help. i finally got it to work with mozilla. thanks guys!for reference purposes here is a code that works- courtesy of the guys here on this thread- for mozilla when using IFRAME contentDocument for rich-text editing:when extracting the innerHTML for whatever purposes - function getFramecontent(aID) { var rv = null; if (document.getElementById(aID).contentDocument){ rv = document.getElementById(aID).contentDocument; // - this line captured by mozilla } else { // IE rv = document.frames[aID].document; }alert(rv.body.innerHTML); }always glad :)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...