Determine that the webpage window appears only once Based on the cookie

Source: Internet
Author: User

This is the JS Code based on the cookie. It is collected from the Internet and is not tested in multiple browsers. The webpage window in IE is only displayed once.

Usage:

1. Add the following code to the head section of the webpage.

<SCRIPT language = "JavaScript">
Function openpopup (){
Window. open ('HTTP: // www.bkjia.com /')
}
Function get_cookie (Name ){
Var search = Name + "="
Var returnvalue = "";
If (document. cookie. length> 0 ){
Offset = document. cookie. indexOf (search)
If (offset! =-1 ){
Offset + = search. length
End = document. cookie. indexOf (";", offset );
If (end =-1)
End = document. cookie. length;
Returnvalue = unescape (document. cookie. substring (offset, end ))
}
}
Return returnvalue;
}
Function loadpopup (){
If (get_cookie ('popped') = ''){
Openpopup ()
Document. cookie = "popped = yes"
}
}
</SCRIPT>

2. Put the red code in the following code in the body, as follows.

<BodyOnunload = "loadpopup ()">

Demo:

<SCRIPT language = "JavaScript"> function openpopup () {window. open ('HTTP: // www.bkjia.com/')} function get_cookie (Name) {var search = Name + "=" var returnvalue = ""; if (document. cookie. length> 0) {offset = document. cookie. indexOf (search) if (offset! =-1) {offset + = search. lengthend = document. cookie. indexOf (";", offset); if (end =-1) end = document. cookie. length; returnvalue = unescape (document. cookie. substring (offset, end)} return returnvalue;} function loadpopup () {if (get_cookie ('popped') = '') {openpopup () document. cookie = "popped = yes" }}</SCRIPT> <body onunload = "loadpopup ()"> <br/> <center> If the effect cannot be displayed, press Ctrl + F5 to refresh the page. For more webpage code: <a href = 'HTTP: // www.bkjia.com/'target = '_ blank'> http://www.bkjia.com/</a> </center>

Tip: the code can be modified before running!

Related Article

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.