碧海潮声大学生网

标题: 【笨笨出品】Hack——快速回帖时保存内容,以防提交出错(cookie) [打印本页]

作者: 笨笨啊    时间: 2006-9-6 03:11
标题: 【笨笨出品】Hack——快速回帖时保存内容,以防提交出错(cookie)
本帖已同步发布于PW官方论坛
http://www.phpwind.net/read-htm-tid-258497.html
本论坛(碧海潮声)已启用此功能

Hack名称:快速回帖时保存内容,以防提交出错
适合版本:pw 4.3.2
安装程序:笨笨啊
安装难易:简单
hack特点:快速回复时能自动保存内容,当提交出错时可以自己选择恢复之前的数据。好处就在于是保存在cookie中,而非是保存在剪切板中,这样就不会覆盖原来剪切板中的内容了
增加表  :无
影响字段:无
增加文件:无
修改文件:

template/wind/fastpost.htm




打开template/wind/fastpost.htm

找到
  1. <!--<?php print <<<EOT
  2. -->
复制代码


在后面加上
  1. <script language="javascript">
  2. function writeCookie(name, value, hours)
  3. {
  4.   var expire = "";
  5.   if(hours != null)
  6.   {
  7.    expire = new Date((new Date()).getTime() + hours * 3600000);
  8.    expire = "; expires=" + expire.toGMTString();
  9.   }
  10.   document.cookie = name + "=" + escape(value) + expire;
  11. }
  12. function readCookie(name)
  13. {
  14.   var cookieValue = "";
  15.   var search = name + "=";
  16.   if(document.cookie.length > 0)
  17.   {
  18.    offset = document.cookie.indexOf(search);
  19.    if (offset != -1)
  20.    {
  21.     offset += search.length;
  22.     end = document.cookie.indexOf(";", offset);
  23.     if (end == -1) end = document.cookie.length;
  24.     cookieValue = unescape(document.cookie.substring(offset, end))
  25.    }
  26.   }
  27.   return cookieValue;
  28. }
  29. </script>
复制代码



找到
  1. <input type=checkbox name="atc_usesign" value="1" checked>使用签名
复制代码

在其前面加上
  1. <a style="cursor:hand"  onclick="javascript:if(confirm(&#39;您确定要恢复上次回帖记录吗?&#39;)) {document.FORM.atc_content.value=readCookie(&#39;lastcontent&#39;);alert(&#39;恢复成功&#39;);document.FORM.atc_content.focus();}">[恢复上次回帖数据]</a>
复制代码


找到
  1. function checkCnt(){
复制代码


在后面加上
  1. writeCookie(&#39;lastcontent&#39;,document.FORM.atc_content.value,24);
复制代码



好处在于是保存在cookie而非剪切板中,不会破坏原有的剪切板内容
作者: 海院の水水    时间: 2006-9-6 08:05
高手就是高手```顶了```




欢迎光临 碧海潮声大学生网 (http://www.zjoubbs.com/) Powered by Discuz! X3.2