[9. Ultimate application-Cookie control in the pop-up window]
In retrospect, although the pop-up window above is cool, there is a small problem (immersed in joy, there is no discovery ?) For example, if you place the above script in a page that requires frequent access (such as the homepage), the window will pop up every time you refresh the page, isn't it very annoying? :-(
Is there a solution? Of course! We can use cookies to control it. First, add the following code to the HEAD area of the HTML homepage:
<Script> 〉
Function openwin (){
Window. open ("page.html", "", "width = 200, height = 200 ")
}
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') = ''){
Openwin ()
Document. cookie = "popped = yes"
}
}
</Script> 〉
Then, use <body onload = "loadpopup ()"> (not openwin, but loadpop !) Replace the original "BODY" sentence on the home page. You can refresh the page or enter the page again, and the window will no longer pop up. Real Pop-Only-Once!
The creation and application skills of the pop-up window are basically completed, and I am exhausted. I have said so much in one breath, I hope that my friends who are making web pages will be very pleased.
It should be noted that the case sensitivity in JS scripts should be consistent before and after