国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > JS > 正文

JS通過Cookie判斷頁面是否為首次打開

2024-05-06 16:28:01
字體:
來源:轉載
供稿:網友
這篇文章主要介紹了JS通過Cookie判斷頁面是否為首次打開 的相關資料,需要的朋友可以參考下
 

廢話不多說了,直接給大家貼代碼了,本文寫的不好還請各位大俠見諒。

JScript code:

function Cookie(key,value){this.key=key;if(value!=null){this.value=escape(value);}this.expiresTime=null;this.domain=null;this.path="/";this.secure=null;}Cookie.prototype.setValue=function(value){this.value=escape(value);}Cookie.prototype.getValue=function(){return (this.value);}Cookie.prototype.setExpiresTime=function(time){this.expiresTime=time;}Cookie.prototype.getExpiresTime=function(){return this.expiresTime;}Cookie.prototype.setDomain=function(domain){this.domain=domain;}Cookie.prototype.getDomain=function(){return this.domain;}Cookie.prototype.setPath=function(path){this.path=path;}Cookie.prototype.getPath=function(){return this.path;}Cookie.prototype.Write=function(v){if(v!=null){this.setValue(v);}var ck=this.key+"="+this.value;if(this.expiresTime!=null){try{ck+=";expires="+this.expiresTime.toUTCString();;}catch(err){alert("expiresTime參數錯誤");}}if(this.domain!=null){ck+=";domain="+this.domain;}if(this.path!=null){ck+=";path="+this.path;}if(this.secure!=null){ck+=";secure";}document.cookie=ck;}Cookie.prototype.Read=function(){try{var cks=document.cookie.split("; ");var i=0;for(i=0;i <cks.length;i++){var ck=cks[i];var fields=ck.split("=");if(fields[0]==this.key){this.value=fields[1];return (this.value);}}return null;}catch(err){alert("cookie讀取錯誤");return null;}}

HTML code:

<script type="text/javascript" src="Cookie.js"></script><script type="text/javascript" language="javascript">window.onload=function(){var ck=new Cookie("HasLoaded"); //每個頁面的new Cookie名HasLoaded不能相同if(ck.Read()==null){//未加載過,Cookie內容為空alert("首次打開頁面");//設置保存時間var dd = new Date();dd = new Date(dd.getYear() + 1900, dd.getMonth(), dd.getDate());dd.setDate(dd.getDate() + 365);ck.setExpiresTime(dd);ck.Write("true"); //設置Cookie。只要IE不關閉,Cookie就一直存在}else{//Cookie存在,表示頁面是被刷新的alert("頁面刷新");}}</script>

以上所述是小編給大家分享JS通過Cookie判斷頁面是否為首次打開的相關內容,希望對大家有所幫助。



注:相關教程知識閱讀請移步到JavaScript/Ajax教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 吴桥县| 卢龙县| 安国市| 贵南县| 垦利县| 广水市| 延边| 合水县| 孟州市| 阳城县| 仁怀市| 天气| 明溪县| 澄江县| 顺平县| 抚顺市| 乌拉特后旗| 贵德县| 辉县市| 广元市| 梅河口市| 宁都县| 夏河县| 花垣县| 特克斯县| 宜兰市| 无棣县| 工布江达县| 德惠市| 宾阳县| 西和县| 天长市| 肥西县| 清河县| 定陶县| 通辽市| 上林县| 名山县| 蚌埠市| 罗田县| 五莲县|