有时为了某种需要,要求进入一个页面时弹出一个窗口.但每次进入时都会弹出,就使人感受到烦.怎样实只弹出一次呢?下面的程序将实现浏览才第一次访问这页时弹出窗口,以后再进入则不会弹出. 在<head>…..</head>之间加入下列代码: <script languang="javascript"> function openpopup(){ window.open("hello.htm","","width=300,height=300") //自己修改弹出窗口 } function get_cookie(Name) { var search = Name + "=" var returnvalue = ""; if (document.cookie.length > 0) { offset = document.cookie.indexOf(search) if (offset != -1) { // if cookie exists offset += search.length // set index of beginning of value end = document.cookie.indexOf(";", offset); // set index of end of cookie value 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区: <body onload="loadpopup()"> //pop when enter page
|