Solve the refresh problem with the hash Parameter
<! Doctype html public "-// W3C // dtd html 4.0 Transitional // EN">
<Html>
<Head>
<Title> New document </title>
<Script language = "JavaScript" type = "text/javascript">
<! --
// Define the refresh processing class and constructor
Function BookMarkFixer (){
// Which functions are used to store status information
This. actions = {};
}
// Register a function that requires refreshing and locating. s indicates the identifier of the function.
BookMarkFixer. prototype. register = function (s, action ){
This. actions [s] = action;
}
// Each registered method needs to display the changed browser tag address during call.
BookMarkFixer. prototype. toHash = function (s ){
Var hash = document. location. hash;
Hash = hash. slice (1, hash. length );
Var arrHash = hash. split (".");
If (hash. length = 0) arrHash = [];
Var exist = false;
// If the function already exists in the Hash address, you do not need to add it again.
For (var I = 0; I <arrHash. length; I ++ ){
If (arrHash [I] = s ){
Exist = true;
Break;
}
}
If (! Exist) arrHash. push (s );
Document. location. hash = "#" + arrHash. join (".");
}
Var bmf = new BookMarkFixer ();
// Restore the status based on the tag data of the browser
Function bmfOnload (){
// Obtain the hash address
Var hash1 = document. location. hash;
Hash1 = hash1.slice (1, hash1.length );
Var arrHash1 = hash1.split (".");
If (hash1.length = 0) arrHash1 = [];
For (var I = 0; I <arrHash1.length; I ++ ){
Bmf. actions [arrHash1 [I] ();
}
}
If (window. attachEvent ){
Window. attachEvent ("onload", bmfOnload );
} Else {
Window. addEventListener ("load", bmfOnload, true );
}
Bmf. register ("p1", setP1 );
Bmf. register ("p2", setP2 );
Bmf. register ("p3", setP3 );
// Defines the function, used to set the content of the specified id Node
Function setContent (containerId, content ){
Container = document. getElementById (containerId );
Container. innerHTML = content;
}
// Set the content of the <p> node whose id is p1
Function setP1 (){
SetContent ("p1", "here is p1 content ");
// Add the status to the Hash Parameter
Bmf. toHash ("p1 ");
}
// Set the content of the <p> node whose id is p2
Function setP2 (){
SetContent ("p2", "here is p2 content ");
// Add the status to the Hash Parameter
Bmf. toHash ("p2 ");
}
// Set the content of the <p> node whose id is p3
Function setP3 (){
SetContent ("p3", "here is p3 content ");
// Add the status to the Hash Parameter
Bmf. toHash ("p3 ");
}
// -->
</Script>
</Head>
<Body>
<A href = "javascript: void (0)" onclick = "setP1 ()"> link1 </a>
<A href = "javascript: void (0)" onclick = "setP2 ()"> link2 </a>
<A href = "javascript: void (0)" onclick = "setP3 ()"> link3 </a>
<P id = "p1"> p1 </p>
<P id = "p2"> p2 </p>
<P id = "p3"> p3 </p>
</Body>
</Html>
<Script language = "JavaScript" type = "text/javascript">
<! --
// Alert (document. location. hash );
// -->
</Script>