Saturday, May 11, 2024
 Popular · Latest · Hot · Upcoming
14
rated 0 times [  19] [ 5]  / answers: 1 / hits: 15652  / 15 Years ago, thu, may 14, 2009, 12:00:00

In testing document.location.href, I have observed that when the user initiates an action that results in javascript that assigns to document.location.href, the new URL is added to the history.



However, if the call is initiated by javascript that is result of, say, state change of an XMLHTTPRequest, the entry for the current page in the history is over-written. Have I characterized this correctly? Is there a way to get the page change to be reflected in the history in this latter case?


More From » javascript

 Answers
6

I was facing the same problem and found this workaround which worked for me



instead of



function onAjaxCallback(evt){
location.href=newLocation;
}


i wrapped the location.href call around a setTimeout. Seems to do the trick. My history's behaving fine now. Hope that helps



function onAjaxCallback(evt){
setTimeout(function(){
location.href=newLocation;
},0)
}

[#99535] Sunday, May 10, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jaelynncherokeeg

Total Points: 697
Total Questions: 109
Total Answers: 104

Location: France
Member since Thu, Mar 18, 2021
3 Years ago
jaelynncherokeeg questions
Thu, May 27, 21, 00:00, 3 Years ago
Fri, Jan 24, 20, 00:00, 4 Years ago
Thu, Nov 14, 19, 00:00, 5 Years ago
Wed, Sep 18, 19, 00:00, 5 Years ago
;