Quick Get/Set several JS implementation methods for object elements in IFrame _javascript tips

Source: Internet
Author: User

1, IE-specific (through the frames Index image positioning): Document.frames[i].document.getelementbyid (' element id ');

2, IE-specific (through the name image of the IFRAME positioning): document.frames[' iframe name '].document.getelementbyid (' element id ');

The above method not only applies to the IFRAME, but also applies to the frame in the frameset. IE is good at customizing standards, but it has to say that many of the design is still relatively human. This, for example, provides a concise and figurative representation of the same standard path that is supported below.

3, the common method: document.getElementById (' The ID of the IFRAME '). ContentWindow.document.getElementById (' ID of element ')

Note that to add Contentwindow, often the problem is because this is easy to ignore, it represents the frame and inside the IFrame window object.

But, obviously, the wording was very, very long. If you want to operate a series of elements inside, so it is enough to write, even with copy and paste Dafa, the eye is also a problem.

4, the general method of shorthand:

Define a short name for document.getElementById, and friends who are slightly familiar with JS know this method. Here it can play a double role, as in the following example:

var $id =document.getelementbyid;
$Id (' The ID of the IFRAME '). Contentwindow. $Id (' ID of element ')//* So you get the object you want to take

At this point, I still like IE practice, more care. Because Microsoft is not a separate browser developer, it also has to write a large number of development html/asp documents, so compare can do this. and other browser developers, basically just stand in a browser position, the most basic link to the finished, and rarely stand in the developer's position to design some such a simple and semantic shortcuts. Many people often say that their "standards" are justified in some places, but in some places such standards are merely indifference.

The above quick get/Set the object element in the IFRAME several JS implementation method is small series to share all the content, hope to give you a reference, also hope that we support cloud habitat community.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.