Closed
Bug 677686
Opened 15 years ago
Closed 15 years ago
history.replaceState in window beforeunload changes the history state for both the next and current page
Categories
(Firefox :: General, defect)
Tracking
()
RESOLVED
INVALID
People
(Reporter: alan.khalis, Unassigned)
Details
User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.107 Safari/535.1
Steps to reproduce:
http://jsfiddle.net/valeshino/mth9k/1/show/
Click the link, then click back, then forward.
Actual results:
The history elements for both the previous and current page are now changed to ?bar=1.
Expected results:
The initial page's history element should be changed to ?bar=1 and the following page should have its history element left in tact.
(using jQuery for simplicity)
$(window).bind('beforeunload', function() {
window.history.replaceState({}, 'replaced', '?bar=1');
});
The replaceState call is made in the context of the current document, so it should only affect the current document's history.
| Reporter | ||
Comment 1•15 years ago
|
||
This seems to be a bug in chrome / safari as well, bug report:
https://bugs.webkit.org/show_bug.cgi?id=65895
| Reporter | ||
Comment 2•15 years ago
|
||
And just minutes ago, it was resolved. The test case in incorrect.
Status: UNCONFIRMED → RESOLVED
Closed: 15 years ago
Resolution: --- → INVALID
I noticed the same problem. It works fine if one clicks back/forward. But on page reload it seems to be misbehaving. Firefox already saves the url that needs to be reloaded, and doesn't take into account the url change eventhough it is processed in the beforeunload event; the state is however updated properly.
$(function(){
if ( window.history.state != null ) $( "#content" ).html( window.history.state.value );
$( window ).bind( "beforeunload", function(e) { window.history.replaceState( { value:"remember me"}, "", document.location.href + "?param=rememberme" ); });
});
I have a test page on: http://www.braikar.com/stuff/test.html
Reload the page twice and you'll see the problem, the url should have been updated on the first reload, not the second? (the state is updated correctly on page reload)
Also another small bug I found, is that if you start writing an url in the browser bar but then leave it incomplete, replaceState({},"","newurl") or pushState({},"","newurl") will not show the change in the bar, the incomplete url will remain there until one goes back/forward in history or reloads.
Try the test page.
You need to log in
before you can comment on or make changes to this bug.
Description
•