The jquery iframe operation is parsed in detail

  • 2020-03-29 23:49:56
  • OfStack

Use jquery to manipulate the iframe

There are two ifame in the content

< The iframe id = "leftiframe"... < / iframe>
< The iframe id = "mainiframe.. < / iframe>

JQuery in leftiframe changes the SRC code of mainiframe:
$(" # mainframe ", the parent. The document. The body). Attr (" SRC ", "http://www.radys.cn")

2. If the content contains an ifame with the ID mainiframe
  < The iframe id = "mainifame"... > < / ifame>
Ifame contains a someID
< Div id = "someID" > You want to get this content< / div>
Get the content of someID

  $(" # mainiframe "). The contents (.), find (" someID "). The HTML () HTML or $(" # mainiframe "). The contains (). The find (" someID "). The text () value

3. In the parent window, select all radio buttons in the IFRAME
$(window frames [r]. "iframe1" document), find (" input [@ type = 'radio'] "). The attr (" checked ", "true");

The natural choice for id is to still use the find method
$(window frames [r]. "iframe1" document), find (" # id ")

4. As shown above
    The jQuery operation in leftiframe is the content of the content of someID of the mainiframe
    $(" # mainframe ", the parent. The document. The body). The contents (.), find (" someID "). The HTML () and $(" # mainframe ", the parent. The document. The body). The contents (.), find (" someID "). Val ()

Manipulate iframes with JavaScript

Cross-reference between frameworks

All frames in a page are provided as properties of window objects in the form of a collection. For example, window.frames represents the collection of all frames on the page. This is similar to form objects, link objects, picture objects, etc., except that these collections are properties of documents. Therefore, to refer to a subframe, use the following syntax:

Window. Frames [" frameName "];

Window. The frames. FrameName

Window. Frames [index]

The word "window" can also be replaced or omitted by self. If frameName is the first frame on the page, the following is equivalent:

Self. -- [" frameName "]

The self. The frames [0]

Frames [0]

frameName

Each frame corresponds to an HTML page, so this frame is also a separate browser window, which has all the properties of a window. A reference to a frame is a reference to a 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 in the frame, and so on.

The following are the cross-references between different hierarchical frameworks:

1. Parent frame to child frame reference

Knowing the above principle, it is very easy to refer to the child framework from the parent framework, that is:

Window. Frames [" frameName "];

This references the frameName subframe on the page. If you want to refer to the subframe within the subframe, according to the nature that the frame referenced is actually the window object, you can achieve the following:

Window. The frames [r]. "frameName" frames (" frameName2 ");

This refers to a second-level subframe, and by extension, a reference to a multilevel frame.

2. A reference from the child frame to the parent frame

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

3. References between brother frames

If two frames are subframes of the same frame, they are called sibling frames and can be cross-referenced by the parent frame. For example, a page contains two subframes:

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

< Frame SRC = "1. HTML" name = "frame1" / >

< Frame SRC = "2. HTML" name = "frame2" / >

< / frameset>

Frame1 can be referenced to frame2 using the following statement:

The self. The parent. Frames (" frame2 "),

4. Cross-references between frameworks at different levels

The hierarchy of the framework is for the top-level framework. When there are different levels, as long as you know your level and the level and name of another framework, you can easily access each other by using the properties of window objects referenced by the framework, such as:

The self. The parent. Frames [r]. "childName" frames (" targetFrameName ");

5. A reference to the top-level framework

Like the parent attribute, the window object also has a top attribute. It represents a reference to the top-level framework, which can be used to determine whether a framework is itself a top-level framework, for example:

// determines whether the framework is the top-level framework

If (self = = top) {

/ / dosomething

}


Related articles: