I am in debug mode, so I can see which page is being hit.
When I call either window.location or window.location.replace(..) it goes to the page, but then back to the originating page!
How could this be??
The solution was to add:
window.location.replace(...);
return false;
Why does return false make this work properly now?
If this script happened on an
onclickoronsubmitevent, then no return or returningtruewill indicate that the browser should take the default action for the link/form. So, if you had anonclickhandler like:Then the browser will go to Yahoo, then see that it should execute the link’s other action (navigating to Google). When you indicate
return false;, the browser knows not to execute the next/default action.So, why does
return false;make this work?For any event hander, to return
trueindicates to continue as normal and to returnfalsemeans to stop trying to handle the event (prevents default handling and stops propagation), though there are arguments against usingreturn false;.