Ajax| Web page
After doing a project in Ajax, the tester told me that after a lot of pages in the news list, when you look at the details of a piece of news and return to the table of contents, you can't go back to the page number you've turned over, and it's depressing to flip it from the first page. Online to find a < develop a standard browser features of the AJAX application > article, according to the introduction, the response code excerpt, retained here.
I realize the principle is: every time the page, the current page number into a fragmented URL fragment logo, the guest after viewing the details returned to the table of contents, in the directory of the body of the OnLoad event to execute Setoptionvalue, the content of the fragments get down, and then perform the function of reading the directory To achieve the ability to save paging information.
Use the fragment identifier portion of the URI to create a history of the State;
function Makehistory (Newhash)
{
Window.location.hash = Newhash;
Expectedhash = Window.location.hash;
alert (Expectedhash);
return true;
}
To 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;
}
Get the contents of the fragment to do anything
function Setoptionvalue (value)
{
var myForm = document.make_history;
var myselect = myform.change_year;
Myselect.options[value-1].selected = true;
document.getElementById ("Testdiv"). InnerHTML = Value.replace (' # ', ');
Test (Value.replace (' # ', ') ");
Alert (Value.replace (' # ', ') ");
return true;
}