通过cookies和meta标签自动跳转实现网页只展示一次

首先打开第一个1.html页面

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 unescape(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            window.onload=function(){                var ck=new Cookie("HasLoaded");                if(ck.Read()==null){//未加载过,Cookie内容为空                                window.location.assign("http://localhost/1/2.html");                ck.Write("true");  //设置Cookie。只要IE不关闭,Cookie就一直存在                }                else{//Cookie存在,表示页面是被刷新的                                alert("页面刷新,不在显示该效果");                }            }              这个页面用来判断是否是第一次打开,是的话则跳转到新页面

2.html,否则不处理.在2.html的head部分加上      这句即可,上面这句的意思是4秒后跳回本页面,跳回之后因为不是首次打开页面了,所以不会再次跳转页面.      虽然这样是实现了这个功能,但是使用了跳转方式,对搜索引擎或许不怎么友好= =

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 单例模式 适用场景:可能会在场景中使用到对象,但只有一个实例,加载时并不主动创建,需要时才创建 最常见的单例模式,...
    Obeing阅读 2,135评论 1 10
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,246评论 19 139
  • 工厂模式类似于现实生活中的工厂可以产生大量相似的商品,去做同样的事情,实现同样的效果;这时候需要使用工厂模式。简单...
    舟渔行舟阅读 7,957评论 2 17
  • 她把我从盒子里唤起 走进白色的房间 干净的座位 建在隐秘的花苞中 浮在天空 尽管 做梦就该做得大一点 可她总是还穿...
    草茅阅读 234评论 2 4
  • 喂,东来我以后结婚你准备送我什么? 结婚送钻戒啊。啪..一掌拍身上故意恼怒道,说 你窥伺本宫多久了?我呸,我只是你...
    浮生安即阅读 139评论 1 0