Several methods of realizing local refresh in JavaScript with iframe summary _javascript tips

Source: Internet
Author: User

An IFRAME is a framed form of embedded web pages that can be refreshed partially by changing the embedded part.

The use of IFRAME is similar to the normal tag element Div, which specifies the position, color, interface layout, etc. embedded in the page.

One, IFrame realizes the local refreshing method one

<script type= "Text/javascript" >
 $ (function () {
 $ ("#a1"). Click (function () {
  var name= $ (this). attr ("name");
  $ ("#iframe"). attr ("src", name). Ready ();
 })
 $ ("#a2"). Click (function () {
  var name= $ (this). attr ("name");
  $ ("#iframe"). attr ("src", name). Ready ();
 })
</script>
<a href= "#" id= "A1" Name= "a1.html" >1</a>
<a href= "#" id= "A2" Name= "A2.html" >2</a>

When the point A1 in the IFRAME Display a1.html content, point A2 in the IFRAME display a2.html content

Two, the method of realizing local refreshing of IFrame two

<a href= "a1.html" id= "A1" Name= "a1.html" target= "i" >1</a> <a href= "a2.html" id= "A2" Name= "A2.html"
target= "I" >2</a>

Note: <form> also has the target attribute, which functions as <a> the same way if <from> or <a> Commit to an action and then jump to the a1.html effect, if there is req.set or session.set in the action, the last in the IFrame can also be displayed.

Three: The method of implementing local refresh by IFRAME three:

<iframe src= "1.htm" name= "Ifrmname" 
id= "Ifrmid" ></iframe>

Scenario One: Use the name attribute of the IFRAME to locate

<input type= "button" name= button "value=" button "onclick=" Document.frames (' Ifrmname '). Location.reload () ">

Or

<input type= "button" name= "button" value= "button" onclick= "Document.all.ifrmname.document.location.reload" () " >

Scenario Two: Using the id attribute of the IFRAME to locate

<input type= "button" name= "button" value= "button" onclick= "Ifrmid.window.location.reload ()" >

Solution III: When the SRC is the other web site address (cross-domain operation)

<input type= "button" name= "button" value= "button" onclick= "window.open (document.all.ifrmname.src, ' ifrmname ', '") ">

Scenario Four: Partial refresh through and replace the SRC of the IFRAME

You can use document.getElementById ("Iframname"). src= "" to redirect the IFrame;

The sample code is as follows: test.html

<! DOCTYPE html>  

The above content to introduce a JavaScript in the IFRAME to achieve local refresh of several methods summarized, I hope that we choose according to their own needs, have any questions welcome to my message, thank you!

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.