Of iframe operation code

  • 2020-03-30 04:10:45
  • OfStack

Common codes:


<iframe src="http://www.baidu.com" marginwidth="0" marginheight="0" border="0"
	scrolling="no" frameborder="0"
	width="350" height="270"></iframe>

<iframe src="//www.jb51.net/plugins/like.php?href=YOUR_URL"
    scrolling="no" frameborder="0"
    style="border:none; width:450px; height:80px"></iframe>

Javascript accesses the orientation of the frame,iframe frame, and href

A frame.

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:


//Determine whether the framework is the top-level framework
if(self==top){
    //dosomething
}

namely


if (window.top!=window.self) {
    // dosomething
}

Change the loading page of the frame

A reference to the framework is a reference to the window object. The location property of the window object can be used to change the navigation of the framework, for example:

Window. The frames [0]. Location = "1. HTML";

References JavaScript variables and functions within other frameworks

Before introducing techniques for referencing JavaScript variables and functions in other frameworks, let's look at the following code:


<script language= " JavaScript "  type= " text/javascript " >
<! � 
function hello(){
  alert( " hello,ajax! " );
}
window.hello();
// � >
</script>

2. The iframe

Strictly speaking, you should use the frames array, and document.all.


<iframe id=myiframe src= " about:<input type=checkbox name=mycheckbox value=mycheckbox> " ></iframe>
<input type=button onclick= " alert(document.frames.myiframe.document.all.mycheckbox.checked) " >

Three href.

Such as:

< A href = "javascript: void (0)" onclick = "linkChangePwd ()" > Change password < / a>

Adjust the height of the frame


window.onload = function() {
 parent.document.getElementById('customiframe').style.height = document.body.clientHeight + "px";
}


Related articles: