SitePoint Sponsor |
|
User Tag List
Results 1 to 4 of 4
-
Oct 15, 2007, 01:35 #1
iframe problem: Can read contents with innerHTML, but cannot insert.
I can read the contents of an iframe:
HTML Code:var iframe = document.getElementById("message"); var iframeContents = iframe.contentDocument.body.innerHTML; var txtarea = document.getElementById('message2'); txtarea.value = iframeContents;
iframe is editable, and content is entered by the user. Still, this works.
But, below code is not working. Trying to put some content to an iframe, with the same innerHTML method above. It returns no errors or warnings. Even last alert() displays "<div>lorem ipsum</div>", but iframe is empty, it displays nothing..
HTML Code:var textContent = "lorem ipsum"; var iframe2 = document.getElementById('message'); iframe2.contentDocument.body.innerHTML = '<div>'+textContent+'</div>'; alert(iframe.contentDocument.body.innerHTML);
H u m o
Uncensored Forums for Intelligent People
-
Oct 15, 2007, 02:31 #2
Sorry guys, I found the problem.
It was the speed of the executing the script, again....
It proceeds and executes next line, without receiving the results of the current line.
JavaScript seems to have this problem if you create elements on the fly with createElement function. I put the above script into a function, and set a timeout: setTimeout(delayInsert,250) and problem solved.H u m o
Uncensored Forums for Intelligent People
-
Dec 9, 2007, 01:54 #3
- Join Date
- Mar 2004
- Posts
- 1,647
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Code:with(iFrame) { onreadystatechange = function() { this.contentDocument.body.innerHTML = "blabla"; } }
any suggestion wellcome!!!
thanx in advance
regards
-
Dec 9, 2007, 07:55 #4
- Join Date
- Nov 2004
- Location
- NJ
- Posts
- 98
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hi reminder,
I believe that the onreadystatechange and others like it such as oncontentready are exclusive to ie. Check out this link:
http://msdn2.microsoft.com/en-us/library/aa360250.aspxLast edited by hddd12345678910; Dec 9, 2007 at 07:57. Reason: Wrong Salutation
Bookmarks