Add session functionality for static page HTML __html

Source: Internet
Author: User
Tags sessions blank page
In general, only server-side CGI programs (ASP, PHP, JSP) have session sessions to hold the active data information of the user during the site (session), and for a large number of static pages (HTML), Can only use the client's cookies to save temporary activity data, but for the operation of cookies is a very cumbersome process, far from the session operation as simple as that.
 
To this end, this article recommends to the reader a solution "persistence technology" in DHTML, which enables session sessions to be used in static pages.
 
Using retention (persistence) technology allows us to save some data objects to the client during the current session, which reduces the access requests to the server, gives full play to the data processing capability of the client computer, and thus improves the efficiency of the page display as a whole.
 
Microsoft Internet Explorer 5 browsers and later versions support the use of state-keeping (persistence) technology, which can be invoked with the following types of behavior:
savefavorite-save page status and information when the page is added to the Favorites folder
savehistory-save page status and information in the current session
savesnapshot-save page status and information when the page is saved to the hard disk persists
Page state and information directly in the page where users save the Web page to
Their hard disk.
userdata-saves page status and Information page production in XML format in current session
 
Persistence technology breaks the previous tradition of using cookies and sessions, inheriting some of the security policies of previous cookies, as well as increasing the ability to store and manage data. Each of our pages has a 64KB of user data storage capacity and a total 640KB storage limit for each site.
 
The persistence technology stores data formats that conform to XML standards, so you can access data using the GetAttribute and SetAttribute methods in DOM technology.
 
The following is a typical application of the persistence technology, through the analysis of the persistence storage data, so that static pages have validation capabilities.
The actual judgment process is this:
There are three objects: Visitors V, navigation page A, content page C
Visitors v only through the navigation page a link to see content page C;
If the visitor V is through other channels to access the content page C (for example, through the hyperlinks of other websites, directly in the IE Address bar to enter Web site access, etc.), content page C will automatically prompt the copyright information, display a blank page.
 
Specific steps to achieve:
First, add a style to the navigation page to define the persistent class and add the storage function Fnsave to authorize it.
<STYLE>
. userData {Behavior:url (#default #userdata);}
</STYLE>
 
<script language=javascript>
Web programming

function Fnsave () {
Opersistdiv.setattribute ("Bisvalid", "true");
Opersistdiv.save ("Oxmlstore");
}
</SCRIPT>
Define a layer in the <body> and </body> area of the navigation page to identify the persistence object
<div class=userdata id= "Opersistdiv" ></DIV>
Add a statement to the hyperlink properties of the navigation page to invoke the function Fnsave:
<a href= ' redhat2.htm ' onmousedown= "Fnsave ()" >
 
Next, add the validation feature to the content page:
In the content page, add a style to define the persistent class and add the storage function fnload to judge the legality.
<STYLE>
. userData {Behavior:url (#default #userdata);}
</STYLE>
<SCRIPT>
var Bpagevalid=false;
function Fnload () {
Opersistdiv.load ("Oxmlstore");
if ((Opersistdiv.getattribute ("Bisvalid")) && (Opersistdiv.getattribute ("bisvalid") = = "true") {
Bpass=true;
Page templates


}
else{
Bpass=false;
}
Opersistdiv.setattribute ("Bisvalid", "false");
Opersistdiv.save ("Oxmlstore");
if (Bpass==false) {
var serror= "Source is unknown, please visit us via authorized website."
alert (serror);
Location.href= "About:blank";
}
}
</SCRIPT>
Modify the content page <body> area as follows:
<body onload= "Fnload ()" >
<div class=userdata id= "Opersistdiv" ></DIV>
 
From the above example can be seen, through the use of persistence, so that ordinary static content page has a session function, the general insensitive information can be saved by the session in the client.
Use a number of static pages with the session function can accomplish many complex tasks, such as virtual shopping cart, advanced search engine and so on. At the same time, because the previous server-side part of the session task transferred to the client, reducing the amount of data interaction, greatly reducing the burden on the server.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.