Common code:
<iframe src="http://www.baidu.com" marginwidth="0" marginheight="0" scrolling="no" frameborder="0"width="350"></iframe><iframe src="//www.VeVB.COM/plugins/like.php?href=YOUR_URL" scrolling="no" frameborder="0" style="border:none; width:450px; height:80px"></iframe>
JavaScript access to frame, iframe framework and href directions
1.frame
1. References from parent to child frame
Knowing the above principle, it becomes very easy to refer to the child framework from the parent framework, that is:
window.frames["frameName"];
This references the subframe named frameName in the page. If you want to reference the subframe within the subframe, according to the referenced framework, it is actually the nature of the window object, so you can implement it like this:
window.frames["frameName"].frames["frameName2"];
This way, the secondary subframe is referenced, and so on, the reference of multi-layer frameworks can be realized.
2. References from child frame to parent frame
Each window object has a parent property that represents its parent framework. If the framework is already a top-level framework, window.parent also represents the framework itself.
3. Quotes between brothers' frameworks
If two frames are the same subframe of the same frame, they are called sibling frames, and they can be referenced through the parent frame. For example, a page includes 2 subframes:
<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. References between different levels of frameworks
The hierarchy of the framework is for the top-level framework. When the levels are different, just know the level you are in and the level and name of the other framework, and use the properties of the window object referenced by the framework, you can easily access each other, for example:
self.parent.frames["childName"].frames["targetFrameName"];
5. References to top-level frameworks
Similar to the parent property, the window object also has a top property. It represents a reference to the top-level framework, which can be used to determine whether a framework itself is a top-level framework, for example:
The code copy is as follows:
//Judge whether this framework is a top-level framework
if(self==top){
//dosomething
}
Right now
The code copy is as follows:
if (window.top!=window.self) {
// dosomething
}
Change the loading page of the framework
A reference to a frame is a reference to a window object. Using the location property of the window object, you can change the navigation of the frame, for example:
window.frames[0].location = "1.html";
Reference JavaScript variables and functions within other frameworks
Before introducing the techniques of referencing JavaScript variables and functions within other frameworks, let's take a look at the following code:
<script language=”JavaScript” type=”text/javascript”><!function hello(){ alert("hello,ajax!");}window.hello();////script>2.iframe
Strictly, it should be to use frames arrays, and document.all.
The code copy is as follows:
<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
1. The linked onclick event is executed first, followed by the actions under the href attribute (page jump, or javascript pseudo-link);
2. Assuming that there are both href and onclick in the link, if you want the actions under the href attribute not to be executed, onclick must get a return value of false. If you don't believe it, you can comment out the return false in the goGoogle function;
3. If the page is too long and there are scroll bars and you want to perform operations through the linked onclick event. Its href attribute should be set to javascript:void(0); instead of #, which prevents unnecessary page jumps;
4. If a function with a return value is called in the linked href attribute, the content of the current page will be replaced by the return value of this function;
5. There will be some difference when holding down the Shift key.
6. The problem I encountered today is that parentNode cannot be accessed in IE6.0 in the form of href.
7. Try not to use the javascript: protocol as A's href attribute, which will not only cause unnecessary triggering of the window.onbeforeunload event, but will also stop playing gif animation images in IE.
like:
<a href="javascript:void(0)" onclick="linkChangePwd()">Change Password</a>
Adjust the height of the frame
The code copy is as follows:
window.onload = function() {
parent.document.getElementById('customiframe').style.height = document.body.clientHeight + "px";
}