GAE:如何给Micolog增加评论用户信息记忆功能
其实就是增加写入cookie和读取cookie的功能!
给主题文件的comments.html增加js代码
<script>
window.onload = function() {
if (document.cookie != "") {
document.getElementById(‘cookiesbox’).checked=false;
getCookies();
}}
function login()
{
var author=document.getElementById(‘author’).value;
var email=document.getElementById(’email’).value;
var url=document.getElementById(‘url’).value;
if (document.getElementById(‘cookiesbox’).checked) {
setCookies(author, email, url);
}
}
function setCookies(author, email, url) {
var Then = new Date();
Then.setTime(Then.getTime() + 365 * 24 * 60 * 60 * 1000);
document.cookie = "author~" + author + "&#emai~" + email +"&#url~"+ url + "&#;expires~" + Then.toGMTString();
//alert(document.cookie);
}
function getCookies() {
var cookieString = new String(document.cookie);
if (cookieString.indexOf("&#") > 0) {
var cooke = cookieString.split("&#");
document.getElementById("author").value = cooke[0].substring(cooke[0].indexOf("~") + 1, cooke[0].length);
document.getElementById("email").value = cooke[1].substring(cooke[1].indexOf("~") + 1, cooke[1].length);
document.getElementById("url").value = cooke[2].substring(cooke[2].indexOf("~") + 1, cooke[2].length);
}
}
</script>
改<input name="submit" type="submit" id="submit" value="提交留言" onClick="login();"/>此行,增加红色部分。
再在其后 增加
<INPUT TYPE="checkbox" NAME="cookiesbox" id="cookiesbox" checked="ture"/><label for="cookiesbox">记住我</label>
这样可以实现在刷新或者打开其他页面时,保留评论用户信息。
此文我今天做了更改 请看 http://www.houkai.com/2009/07/31/micolog-js-cookie.html
转载链接丢失呀