I worked on several part-time jobs and made an ajax request when I completed the page. When the browser is refreshed, the forward button becomes invalid. As a result, google. Jquery. history. js plug-in to be used
On the shoulders of giants, the following steps forward and backward are completed based on plug-ins!
I worked on several part-time jobs and made an ajax request when I completed the page. When the browser is refreshed, the forward button becomes invalid. As a result, google. Some solutions are found. One of the jquery. hashchange. js plug-ins sometimes becomes invalid, sometimes causing multiple page requests.
In another plug-in test, it perfectly meets my requirements.
The general idea is to add a parameter to the url. All work is done based on this parameter.
The Code is as follows:
// Intercept the required string for the first occurrence of the input string. Content Between fieldName + tag and endTag
Function getQueryString (url, fieldName, tag, endTag ){
Var urlString = url; // document. location. href;
If (urlString! = Null ){
Var typeQu = fieldName + tag;
Var urlEnd = urlString. indexOf (typeQu );
If (urlEnd! =-1 ){
Var paramsUrl = urlString. substring (urlEnd + typeQu. length );
Var isEnd = paramsUrl. indexOf (endTag );
If (isEnd! =-1) {return paramsUrl. substring (0, isEnd );}
Else {return paramsUrl ;}
}
Else {return null ;}
}
Else {return null ;}
}
// Set the default page
Function setDefaultPage (){
$ ("# Contul ul" ).html ("");
$ ("# Contul"). hide ();
$ ("# Cont"). show ();
$ ("# Top span"). find ("a"). removeClass ("active ");
$ ("# Top span: eq (0)"). find ("a"). addClass ("active ");
}
// Check final characters
Function checkCode (getParme ){
If (getParme! = Null ){
GetParme = getParme. toUpperCase ();
Var codeNum = getParme. charCodeAt (0)
}
If (codeNum> = 65 & codeNum <= 91 ){
$ ("# Top span"). find ("a"). removeClass ("active ");
// Alert (codeNum-64 ));
$ ("# Top span: eq (" + (codeNum-64) + ")"). find ("a"). addClass ("active ");
// $ ("# Cont" ).html ("");
$ ("# Cont"). hide ();
$ ("# Contul"). find ("ul" ).html ("");
RunAjaxGetCode (getParme );
} Else {
Setdefapage page ();
}
}
// Perform ajax operations
Function runAjaxGetCode (getParme ){
// $ ("# Cont"). fadeOut ('quick', function (){
$. Ajax ({
Cache: false,
Type: 'get ',
Url: 'sxml/searchbyword' + getParme + '. xml ',
BeforeSend: function (XMLHttpRequest ){
$ ('
Loading data. Please wait.
')
. InsertBefore ($ ("# cont "))
. FadeIn ('slow ');
},
Success: function (data, textStatus ){
$ ("# Contul"). show (). find ("ul" ).html ("");
$ (". Quick-alert"). fadeOut ('low', function (){
$ (This). remove ();
$ ("Item", data). each (function (I, domEle ){
$ ("# Contul ul"). append ("
"+ GetParme +": "+ $ (domEle). children (" title "). text () +"");
If ($ (this). index ()-6) % 6 = 0 ){
$ ("# Contul ul"). append ("
");
}
});
});
},
Error: function (){
Alert ("sorry, data acquisition failed. Please refresh the page F5 and try again \ if the problem persists, contact the website administrator. ");
}
});
//});
}
// Obtain parameters
Function getParmeter (){
GetParme = getQueryString (urlParem, '# javascript = tagCode ("','','")');
CheckCode (getParme );
}
// GetParmeter ();
// Click to trigger
$ ("# Top span: gt (0)"). click (function (){
$ (". Quick-alert"). remove ();
});
// Initialization
$. History. init (function (url ){
// Load (url = ""? "1": url );
If (url. length> 0 ){
GetParme = getQueryString (url, 'javascript = tagCode ("','','")');
If (getParme! = Null ){
GetParme = getParme. toUpperCase ();
CheckCode (getParme );
}
}
Else {
Setdefapage page ();
}
});
// Other operations on the page
Var getParme;
// Function getHash (){
// Var curHash = location. hash;
// Alert (curHash );
//}
Var urlParem;
UrlParem = document. location. href;
Var topHtml;
Var topHtmlLink = "";
Var $ _ objTop;
$ _ ObjTop = $ ("# top ")
Tophtml1_pai_objtop.html ();
For (var I = 65; I <91; I ++)
{
TopHtmlLink + = "" + String. fromCharCode (I) + "";
}
Pai_objtop.html (topHtml + topHtmlLink );
Jquery. history. js plugin Demos
Some demos are available here and have ded in the repository.
And this site itself is built on the plugin:
The Code is as follows:
(Function ($ ){
Var origContent = "";
Function loadContent (hash ){
If (hash! = ""){
If (origContent = ""){
OrigContent = Response ('{content'}.html ();
}
$ ('# Content'). load (hash + ". html ",
Function () {prettyPrint ();});
} Else if (origContent! = ""){
Certificate ('{content'{.html (origContent );
}
}
$ (Document). ready (function (){
$. History. init (loadContent );
$ ('# Navigation A'). click (function (e ){
Var url = $ (this). attr ('href ');
Url = url. replace (/^ .*#/,'');
$. History. load (url );
Return false;
});
});
}) (JQuery );