HTML5 history implement no Refresh page

Source: Internet
Author: User

Note: To run under the server

<body>
<a href= "test1.html" class= "History" > Click I jump to test1.html page </a>
<a href= "index1.html" class= "History" > Click I jump to index1.html page </a>
<a href= "hello.html" class= "History" > Click I jump to hello.html page </a>
<p> The following is the content that will be changed </p>
<div id= "Content" > </div>

<script type= "Text/javascript" >
$ (function () {

$ ('. History '). On (' click ', Function (e) {
This method notifies the Web server that the associated method is not executed
E.preventdefault ();
var href = $ (this). attr (' href ');
Get href
GetContent (href, true);
});

});

The State property of the Listener pushstate () Popstate event object contains a copy of the state object for this history entry.
Window.addeventlistener ("Popstate", function (e) {

Get the status value using E.state
GetContent (Location.pathname, false);//True to change only the path does not change the content
});

function getcontent (URL, a) {
Get path
$.get (URL)
. Do (Funcyion ()) executes the second callback function. Done is the solution to the deferred object that is the JQ callback function
. Done (function (data) {

Change Content
$ (' #content '). HTML (data);

if (a = = True) {
Add historical records
History.pushstate (null, NULL, URL);
}

});
}

</body>

HTML5 history implement no Refresh page

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.