Enable the Ajax web page to have the backend Function
After creating a project in Ajax, the tester told me that after the news list has been turned over many pages, When I view the detailed information of a news record and return it to the directory, it is depressing that you cannot return a page number that has already been turned over from the first page. Find an article <develop an Ajax application that retains the standard browser function> on the Internet, and extract the corresponding code according to the description in the article.
My implementation principle is: each page is turned over, the current page number is saved to the fragment ID of the broken URL, and the customer will return to the directory after viewing the detailed information, in the onload event of the Directory body, execute setoptionvalue to get the fragment content, and then execute the function to read the directory to save the paging information.
// Use the part identifier of the URI to create a history of the status;
Function makehistory (newhash)
{
Window. Location. Hash = newhash;
Expectedhash = Window. Location. Hash;
Alert (expectedhash );
Return true;
}
// Check the URI in the browser history
Function handlehistory ()
{
If (window. Location. Hash! = Expectedhash)
{
Alert (window. Location. Hash + "|" + expectedhash );
Expectedhash = Window. Location. Hash;
VaR newoption = expectedhash;
Setoptionvalue (newoption );
}
Return true;
}
Function pollhash (){
Handlehistory ();
// Window. setinterval ("handlehistory ()", 1000 );
Return true;
}
// Obtain the content in the fragment and perform any operations
Function setoptionvalue (value)
{
// Var myform = Document. make_history;
// Var myselect = myform. change_year;
// Myselect. Options [value-1]. Selected = true;
Document. getelementbyidx ("testdiv"). innerhtml = value. Replace ('#','');
Test (value. Replace ('#',''));
Alert (value. Replace ('#',''));
Return true;
} # JavaScript/ajax Column