Static page because of its stability fast, it does give SE, the user and webmaster brought convenience. But sometimes, you need to remember the user's information, such as the user left a comment, the next time, you should remember the user's information, do not have to enter again.
For users, they can improve their sense of belonging and familiarity. How to achieve it?
First of all, we need to submit a comment after the user to give the client a number of related cookies value, this is very simple, directly in the Comment submission page to assign value on the ASP, the cookie simple assignment method using the following statement:
Copy Code code as follows:
Response.Cookies ("username") = "Name"
Response.Cookies ("username"). expires=date+30
By using the cookies in the above ASP program, we successfully write the user's cookie information to our website. The next thing to do is how to read this cookie in the static page HTML and display it in front of the user. Because it is generated HTML, we can no longer use the ASP program to read this cookie, need to read this cookie through JS, and given to the corresponding input value.
Use JS to read cookies and assign values to the following code:
Copy Code code as follows:
<script type= "Text/javascript" >
JS Get Cookie
var acookie=document.cookie.split (";");
function Getck (sname)
{//Get a single cookie
for (Var i=0;i<acookie.length;i++) {
var arr=acookie[i].split ("=");
if (Sname==arr[0]) {
if (arr.length>1)
Return unescape (arr[1]);
Else
Return "";
}}
Return "";
}
Assign values to the input in the corresponding form
DOCUMENT.FORM_NAME.INPUT_NAME.VALUE=GETCK ("username");
</script>
In this way, the static page can be successfully read from the client's system we have been assigned cookies information, and displayed. is not very simple, hehe. If you have other ideas, welcome to discuss it with me.