Jump to content

Iframe Html


djp1988

Recommended Posts

How can i retreive the html of a document in an iframe with javascript?I've made an editable iframe so people can type up some content for my site and by means of inserting images, I wish for them to do a code and so i need to have a submit button that only sends the html of the newly edited iframe to a php script whici changes [ img] ninto '<img src="' and [/ img] into '" alt="" border="1" />' but I can't find how to retreive the html of the newly modified iframe document...I have tried:

	iframe = document.getElementById("editme").contentDocument || document.getElementById("editme").contentWindow.document;	alert(iframe.innerHTML)

Link to comment
Share on other sites

I have solved this problem, by calling a function that sets variable from the iframe's document returned value, however I have another problem, can i use the execCommand() to insert key words into the document? I wish to have a pull down menu with a list of countries, and if a uer wishes to insert that country as a string, he/she chooses it from the menu and once it has been set, the value of that <option> is inserted as a string to the desired placement in the editable document, is this possible?

Link to comment
Share on other sites

execCommand is now widely supported beyond IE, but you don't want it for this. Here is the correct method for adding an option:

var opt = document.createElement('option');opt.text = "Whatever";opt.value = "Something";var sel = document.getElementById("my_select");try {	sel.add (opt, null); // W3 STANDARD -- NULL APPENDS TO THE END -- PASS AN INDEX TO INSERT} catch (ex) {	sel.add (opt); // IE}

Link to comment
Share on other sites

What I find works in all but IE is the following: iframe:

<script type="text/javascript">function check(){var vera = document.all[0].innerHTML;alert(vera);return vera;}</script>type your text here

parent document:(the iframe has a name="editme" and id="editme")

	text = window.editme.check() || document.frames("editme").document.check();

text = window.editme.check() works fine for all but ie, and after some research, I found on the following link: http://msdn.microsoft.com/en-us/library/ms...58(VS.85).aspx#that ie accesses iframes differently, their exemple:

sColor = document.frames("sFrameName").document.body.style.backgroundColor;

to get the background color of the iframe document, so i tried adding document.frames("editme").document.check(); to access the function in the iFrame, but still no luck,can anyone help ?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...