|
|||||||
| JavaScript JavaScript (not Java) Discussion and technical support, including AJAX and frameworks (JQuery, MooTools, Prototype...) |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Can't get content of the iframe node
I want to display content of the iframe node <mydata>. But it not works, it just display empty message. I work on IE8.
My code: Code:
<html>
<head>
<script type="text/javascript">
function show() {
var v = window.frames['IF'].document.body.innerHTML; //gives empty message
//var v = window.frames['IF'].document.getElementById('MY').firstChild.nodeValue; //gives error
alert(v);
}
</script>
</head>
<body>
<form>
<input type="button" value="but" onclick="show()" />
</form>
<iframe name="IF" id="IF">
<html>
<body>
<mydata id="MY">ala </mydata>
</body>
</html>
</iframe>
</body>
</html>
|
|
#2
|
|||
|
|||
|
I tried also :
var v = window.frames['IF'].mydata; //gives undefined var v = window.frames['IF'].MY; //gives undefined |
|
#3
|
||||
|
||||
|
I guess you missed the way IFRAME element works:
http://www.w3schools.com/TAGS/tag_iframe.asp An IFRAME loads and displays another HTML file into the document |
|
#4
|
|||
|
|||
|
This code is just an example. My program is a servlet and the iframe src is redirected to server with get method. Iframe body is filled by server response. I need to display this response from javascript, so i need to display iframe body.
|
|
#5
|
||||
|
||||
|
Example of what? I see no SRC attribute inside that IFRAME. The way you have written, everything you coded inside <iframe></iframe> is invisible for modern browsers. If you give an example, give a realistic example.
For JavaScript, the accuracy of the HTML code is vital. We need to see what JavaScript sees, and JavaScript sees what the browser shows like on View Source. |
|
#6
|
|||
|
|||
|
It sounds like a backwards way to do AJAX requests. Is there a reason you are using iframes instead of AJAX?
|
|
#7
|
|||
|
|||
|
Quote:
Previously I tried this method: http://www.ibm.com/developerworks/we...rel/index.html Now I used AJAX as you suggested an it works. Thanks. |
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|