Use cookies to make an IFRAME refresh while staying on the current page

Source: Internet
Author: User

This period of time for the first time with the IFRAME, found that the problem is quite many, this time, the main solution is to use a cookie to achieve an IFRAME refresh when staying in the current page, the specific steps are as follows:

1. The current URL must be recorded in each page and stored in a cookie with the following code:

<script>
Record the current page URL
Document. cookie="url=regist_code.html";
</Script>

2. In the main page, read the value of the key ' URL ' in the cookie. The code is as follows:

 <IframeId="Index_frame"Name="Index_frame"Src=""
Width="100%"height="88%"allowtransparency="True"Frameborder="0"ranat="Server"></Iframe>

JS Code
<Script>
Variframe =Document.getElementById (' Index_frame ');
IfIframe.GetAttribute (' src ')! =‘‘){
Iframe.SetAttribute (' Src ',' index.html ');//To determine the first time you enter the page, the first page is displayed, see PS
}
functionGetCookie (URL)
{
if (Document.Cookies.Length>0)
{
VarStrcookie=Document.Cookies;
Cutting multi-Cookie into multiple name/value pairs
VarArrcookie=Strcookie.Split"; ");
Iterate through the cookie array and process each cookie against
ForVarI=0;i<Arrcookie.Lengthi++) {
VarArr=arrcookie[I].Split"=");
//finds a cookie with the name UserID and returns its value
if (Url==arr[< Span style= "COLOR: #0000ff" >0]) {
return ( arr[1]);
break;
}
}
}
}
iframe.setattribute ( ' src ', getcookie ( ' URL '));// Reset get URL, implement refresh display current page
</script ;

PS: This example is to put all the pages, including the homepage, so the first time to enter the page needs to set the IFRAME SRC, if directly in the src write src= "index.html", when the page refresh there will be a delay, Causes the page to appear index.html content before displaying the contents of the other currently clicked page.

Use cookies to make an IFRAME refresh while staying on the current page

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.