By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,848 Members | 3,202 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,848 IT Pros & Developers. It's quick & easy.

Accessing elements of IFrame..

dmjpro
100+
P: 2,476
I want to access the elements of IFrame.
Suppose here is my code ....
Expand|Select|Wrap|Line Numbers
  1. <iframe .... ></iframe>
  2.  
Now i want to access the elements inside the IFrame ..how can i do that ?
Oct 13 '08 #1
Share this Question
Share on Google+
5 Replies


acoder
Expert Mod 15k+
P: 16,027
For standards-compliant browsers, use contentDocument to get access to the document within the iframe. IE requires contentWindow.document.

If you use the window.frames[] syntax, you can just use document.
Oct 13 '08 #2

dmjpro
100+
P: 2,476
For standards-compliant browsers, use contentDocument to get access to the document within the iframe. IE requires contentWindow.document.

If you use the window.frames[] syntax, you can just use document.
Why JavaScript comes up with two flavors?
Oct 15 '08 #3

acoder
Expert Mod 15k+
P: 16,027
No, JavaScript doesn't come with two flavours. Browsers sometimes choose not to implement standards which is where things go wrong and, more often than not, it's IE which is the culprit. There are parts of JavaScript where there are no standards at present. In that case, browsers have to come to some sort of agreement on naming, behaviour, etc.

Edit: did you mean the two different types of syntax?
Oct 15 '08 #4

dmjpro
100+
P: 2,476
No, JavaScript doesn't come with two flavours. Browsers sometimes choose not to implement standards which is where things go wrong and, more often than not, it's IE which is the culprit. There are parts of JavaScript where there are no standards at present. In that case, browsers have to come to some sort of agreement on naming, behaviour, etc.

Edit: did you mean the two different types of syntax?
Sorry you didn't get me ... ;)
Suppose this is my code ..
Expand|Select|Wrap|Line Numbers
  1. <iframe name='_name' id='_id' ... ></iframe>
  2.  
Now i am accessing the document object of IFrame ...
Expand|Select|Wrap|Line Numbers
  1. var doc = document.getElementById('_id').contentDocument; //Mozilla
  2. var doc = document.getElementById('_id').contentWindow.document //IE
  3. var doc = window.frames['_name'].document; //both
  4.  
Now my question is ..that
document.getElementById('_id') and window.frames['_name'] refers the same object ..i mean the iIFrame window.

For one case contentDocument or contentWindow.document and for another case it is cimply document ..why?
This is my question ?
I think you get my question ... ;)
Oct 15 '08 #5

acoder
Expert Mod 15k+
P: 16,027
This link will explain. It boils down to whether it's a frame or an object. The first syntax is used for an object while the second for a frame.
Oct 15 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.