简体   繁体   中英

HTML5 History API and leave page (to same domain)

With media players on site we use the History API and XHR to allow navigation through the site without causing page refreshes (ie causing the media to stop).

This works nicely until the following scenarios:

A. The user changes the URL in the address bar.

B. The user selects a bookmarked page.

C. The user clicks on a Facebook widget that requests another page.

Is there a way to intercept the changed URL and handle it without causing a page refresh, of course we are talking about URLs to the same domain here.

Have there been changes to the window.onbeforeunload event that means we can cancel the leave and obtain the new URL without informing the user?

window.onbeforeunload has not changed. And I think that what you are trying to do is not possible, since that would allow a malicious web page to prevent a user from ever leaving a page (unless he would close the browser/tab).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM