/    Sign up×
Community /Pin to ProfileBookmark

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>
[/CODE]

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@darenoauthorNov 20.2009 — I tried also :

var v = window.frames['IF'].mydata; //gives undefined

var v = window.frames['IF'].MY; //gives undefined
Copy linkTweet thisAlerts:
@KorNov 20.2009 — I guess you missed the way IFRAME element works:

http://www.w3schools.com/TAGS/tag_iframe.asp

An IFRAME loads and displays [I]another[/I] HTML file into the document
Copy linkTweet thisAlerts:
@darenoauthorNov 20.2009 — 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.
Copy linkTweet thisAlerts:
@KorNov 21.2009 — This code is just an example. [/QUOTE]
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.
Copy linkTweet thisAlerts:
@criterion9Nov 22.2009 — It sounds like a backwards way to do AJAX requests. Is there a reason you are using iframes instead of AJAX?
Copy linkTweet thisAlerts:
@darenoauthorNov 23.2009 — It sounds like a backwards way to do AJAX requests. Is there a reason you are using iframes instead of AJAX?[/QUOTE]

You are right criterion9. But I am pl/sql programmer and now I have to write web application and I don't know java script - I didn't know I can use something like AJAX.

Previously I tried this method: http://www.ibm.com/developerworks/web/library/wa-exrel/index.html

Now I used AJAX as you suggested an it works. Thanks.
×

Success!

Help @dareno spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...