2013-10-12 43 views
0

因此,我终于得到了这个奇妙的cookie脚本为我的网站工作www.dynamicdrive.com/forums/showthread.php?69591-Looking-for-aquot不再显示此页再次引用复选框脚本:清除域中所有用户的设置值的单个cookie

// Skip this Page Script (c)2012 John Davenport Scheuer 
     // as first seen in http://www.dynamicdrive.com/forums/ 
     // username: jscheuer1 - This Notice Must Remain for Legal Use 
     ;(function(setting){ 
      var cook = { 
       set: function(n, v, d){ // cook.set takes (name, value, optional_persist_days) - defaults to session if no days specified 
        if(d){var dt = new Date(); 
         dt.setDate(dt.getDate() + d); 
        d = '; expires=' + dt.toGMTString();} 
        document.cookie = n + '=' + escape(v) + (d || '') + '; path=/'; 
       }, 
       get: function(n){ // cook.get takes (name) 
        var c = document.cookie.match('(^|;)\x20*' + n + '=([^;]*)'); 
        return c? unescape(c[2]) : null; 
       } 
      }; 
      if(cook.get('skipthispage')){ 
       //Hide element when cookie exists 
      } 
      else { 
       //Show element when cookie does not exist 
      } 
      if(!document.cookie){cook.set('temp', 1);} 
      if(document.cookie){ 
       jQuery(function($){ 
        $('#optout').css({display: ''}).append(setting.optoutHTML).find('input').click(function(){ 
         this.checked? cook.set('skipthispage', '1', setting.days) : cook.set('skipthispage', '', -1); 
         this.checked && setting.gowhenchecked && location.replace(setting.page); 
        }); 
       }); 
      } 
     })({ 
      days: 1, // days cookie will persist 
      page: '', 
      gowhenchecked: true, // true/false - should page switch when the box is checked? 
      optoutHTML: '<label for="optoutcheckbox">Don\'t show this again: <input type="checkbox" id="optoutcheckbox" value=""></label>' 
     }); 

但是; 我使用这个来隐藏当人们最初访问我的网站时弹出的醒目页面,并且它给了他们使用1天长cookie来隐藏这个醒目页面的选项。

此初始页面包含有关我正在处理的网站的信息,并且它在不断变化。所以,当信息发生变化时,我需要一种快速有效的方式来清除所有Cookie。

所以我需要的是一个按钮,我可以点击我的ACP,清除这些cookie,并再次显示访问我的网站的人的启动页面。

我一直试图让这个工作使用很多不同的方法,但似乎没有工作。

感谢jscheuer1这个可爱的脚本。

问候, 弗雷德里克牛逼


编辑: 我要补充:在ACP位于从哪里脚本是一个子目录。

http://example.com/index.php //这是一个脚本被加载

http://example.com/admin/index.php //这是我需要的按钮是。

如果以上是不可能的,我想我可以使用PHP来只允许显示,如果会话用户设置为管理员。但我想避免这种情况。

回答

0

通过在我的数据库中生成一个64字节的字符串来解决这个问题,以便在发生更改时替换旧值,这是我希望人们能够看到的。

将其绑定到一个字符串并将其插入到Javascript中。