Jquery Operation IFrame

Source: Internet
Author: User

Manipulating an IFRAME using jquery

1. There are two ifame in the content

<iframe id= "Leftiframe" ...</iframe>
<iframe id= "Mainiframe. </iframe>

Leftiframe in jquery changes the SRC code of Mainiframe:
$ ("#mainframe", Parent.document.body). attr ("src", "http://www.radys.cn")

2, if the content has an ID of mainiframe ifame
<iframe id= "Mainifame" ...></ifame>
Ifame contains a Someid
<div id= "Someid" >you want to get this content</div>
Get Someid's content

$ ("#mainiframe"). Contents (). Find ("Someid"). html () HTML or $ ("#mainiframe"). Contains (). Find ("Someid"). Text () value

3. Manipulate all the radio buttons in the selected IFrame in the parent window
$ (window.frames["iframe1"].document). Find ("input[@type = ' Radio ']"). attr ("Checked", "true");

The choice of ID is still using the Find method
$ (window.frames["iframe1"].document). Find ("#id")

4, as shown above
Leftiframe in jquery operations Mainiframe content Someid content
$ ("#mainframe", Parent.document.body). Contents (). Find ("Someid"). HTML () or $ ("#mainframe", Parent.document.body). Contents (). Find ("Someid"). Val ()

Manipulating an IFRAME using JavaScript

Cross-referencing between frames

All frames in a page are provided as a collection of properties for the Window object, for example: Window.frames represents a collection of all frames within that page, similar to form objects, linked objects, picture objects, and so on, which are attributes of the document. Therefore, to reference a child frame, you can use the following syntax:

window.frames["FrameName"];

Window.frames.frameName

Window.frames[index]

Where the Word window can also be replaced or omitted with self, assuming that FrameName is the first frame in the page, the following notation is equivalent:

self.frames["FrameName"]

Self.frames[0]

Frames[0]

FrameName

Each frame corresponds to an HTML page, so the framework is also a separate browser window that has all the properties of the window, and the so-called reference to the frame is a reference to the Window object. With this Window object, you can easily manipulate the pages in it, such as using the Window.document object to write data to the page, using the Window.location property to change the pages within the frame, and so on.

The following sections describe the mutual references between different levels of frames:

1. Parent frame-to-child frame references

Knowing the above principle, it is very easy to refer to a child frame from the parent frame, i.e.:

window.frames["FrameName"];

This refers to a child frame named FrameName within the page. If you want to refer to a child frame within a child frame, according to the referenced frame is actually the nature of the Window object, you can do this:

window.frames["FrameName"].frames["frameName2"];

This refers to the level two sub-framework, and so on, you can implement a multi-layered framework reference.

2. A reference to the parent frame of a child frame

Each Window object has a parent property that represents its parents frame. If the frame is already a top-level frame, window.parent also represents the framework itself.

3. A reference between brothers frames

If two frames are the same as a frame's sub-framework, they are called sibling frames, and can be referenced through the parent framework, such as a page consisting of 2 sub-frames:

<frameset rows= "50%,50%" >

<frame src= "1.html" name= "frame1"/>

<frame src= "2.html" name= "frame2"/>

</frameset>

In Frame1, you can use the following statement to refer to frame2:

self.parent.frames["Frame2"];

4. Mutual references between different levels of frames

The hierarchy of frames is for the top-level framework. When the hierarchy is different, you can easily access each other by the nature of the window object referenced by the framework, as long as you know your level and the hierarchy and name of another frame, for example:

self.parent.frames["ChildName"].frames["Targetframename"];

5. References to top-level frames

Like the Parent property, the Window object also has a top property. It represents a reference to the top-level frame, which can be used to determine whether a frame itself is a top-level frame, for example:

Determine if the frame is a top-level frame

if (self==top) {

DoSomething

}

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.