/    Sign up×
Community /Pin to ProfileBookmark

IFRAME Question….

I have a page with an iFrame named myFrame. I can access the tag properties (like name) like this: window.frames[0].name . Ok, so how do I acces the text inside the iframe. I understand that its basically just another document object but I am lost as how to access it properties.

I have some text in a Div tag named myDiv, so how do I get access to its ‘value’ properties?

Jason

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@pyroFeb 05.2003 — I think something like this might work. In your iFrame, give your div tag an id, then change the elements in [b]bold[/b] to reflect your page. Let me know if it works.

var content = top.[b]iframename[/b].document.getElementById('[b]yourdivid[/b]').innerHTML;

That should throw the content of [b]yourdivid[/b] into the content variable.
Copy linkTweet thisAlerts:
@kj2wauthorFeb 05.2003 — Here is what I got after your post:

Parent Page-

alert(window.frames[0].document.getElementsByName('myDiv').innerHTML);

Page contained in IFRAME-

<div id="myDiv">

test

</div>

Alert Box-

undefined

Any ideas?

Jason
Copy linkTweet thisAlerts:
@gil_davisFeb 05.2003 — [i]Originally posted by kj2w [/i]

[B]Ok, so how do I acces the text inside the iframe.[/b][/quote]
In IE you can use window.myFrame.document.body.innerText.[b]I have some text in a Div tag named myDiv, so how do I get access to its 'value' properties?[/B][/QUOTE]A DIV does not have a "value" property. A FORM element has a "value" property. Are you confused?
Copy linkTweet thisAlerts:
@pyroFeb 05.2003 — A couple of things...First off all, you changed my code. You changed getElementsById to getElementsByName...No wonder it didn't work. Also, don't do window.frames[0] to reference you iFrame. Give the iFrame a name of myiframe like this <iframe name="myiframe" ...> Then do this...

alert(top.myiframe.document.getElementsById('myDiv').innerHTML);
Copy linkTweet thisAlerts:
@kj2wauthorFeb 05.2003 — You were both right. Here is what I got to work:

From Pyro-

alert(window.frames[0].document.getElementById('myDiv').innerHTML);

where 'myFrame' contained-

<body>

<div id="myDiv">

test

</div>

</body>

From Gil Davis-

alert(window.myFrame.document.body.innerHTML);

where 'myFrame' contained-

<body>

test

</body>

Thanks again guys. ?

Jason
×

Success!

Help @kj2w 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.17,
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,
)...