js 弹出框仅弹一次(二次修改之后的)
发布时间:2023-08-03 14:39:47 所属栏目:教程 来源:
导读:弹出框只弹一次,看到网上也就写的很多,但真正能拿过来用的没有几个。以下是我修改之后的代码,供参考。
这段代码是使用了cookie来控制的,首先使用cookie让浏览器记住这个页面已经打开过一次,如果再次引用这个
这段代码是使用了cookie来控制的,首先使用cookie让浏览器记住这个页面已经打开过一次,如果再次引用这个
弹出框只弹一次,看到网上也就写的很多,但真正能拿过来用的没有几个。以下是我修改之后的代码,供参考。 这段代码是使用了cookie来控制的,首先使用cookie让浏览器记住这个页面已经打开过一次,如果再次引用这个页面已经打开一次了,如果再次引用这个页面的话将不进行打开。而浏览器一旦关闭浏览器,保存这个记录的cookie文件将被删除。因此关闭浏览器,再次打开的话弹出窗口还会出现的,从而确保了在原有的窗口基础上只打开一个窗口。 代码如下: <script type="text/javascript"> var returnvalue = ""; function openpopup(){ <s:if test="isAlreadyGetGift == 0"> $.colorbox({inline:true, href:'#getGiftForm',innerWidth:'650px;',innerHeight:'475px;',onOpen:true}); $("#getGiftSuccess").hide(); </s:if> } function get_cookie(Name) { var search = Name + "="; 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 == 10){ end = document.cookie.length; returnvalue=unescape(document.cookie.substring(offset, end)); } } } return returnvalue; } function loadpopup(){ if (get_cookie("popped")==""){ openpopup(); document.cookie="popped=yes" } } $(document).ready(function(){ loadpopup(); }); </script> (编辑:聊城站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐