Allow AJAX Web pages to function backwards

Source: Internet
Author: User
Tags hash response code return window
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;
}



Related Article

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.