The bizarre behavior of mobile-popstate

Source: Internet
Author: User

Since the performance of iOS is better in cached pages, the back of the General page will save the previous history page,

JS on the page is not triggered, so it can trigger to the Popstate event, while some versions of WebKit popstate

The understanding is inconsistent with the official standard, which causes each access page to be synced to the history of this page,

So popstate is triggered, and in the project requires iOS a back Refresh page

Code:

Window.addeventlistener (' Popstate ', function () {    window.location.reload ();});

  

But the page after entering the page constantly triggered the above method, refresh the page, this webkit to Popstate of the strange behavior caused.

The perception of this difference is the cause of the bizarre behavior in WebKit. WebKit did not separate HTML5 's history from the traditional one, and according to the official document's description of Popstate, the popstate is triggered as long as the historical record is accessed. Traditionally, access pages and production history are at the same time. So in WebKit, either refreshing or accessing a new page will trigger popstate. In other browsers, this popstate is used only for the history of HTML5, and does not respond to traditional history, let alone refreshing and accessing new pages.
WORKAROUND: Delay the event load so that the Popstate event is loaded after the page has finished loading.
Window.onload=function () {  setTimeout (function () {  window.addeventlistener (' Popstate ', function () {    Window.location.reload ();});  },0)  }

  

The bizarre behavior of mobile-popstate

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.