I am currently fighting Google Chrome on the following action:
location.href = url
location.replace(url)
document.location = url
window.navigate(url) // doesn't work in Chrome/Firefox
location.assign(url)
window.open(url, '_self')
window.location.href = url
I have tried all, and neither will add a history entry. Is there a way in Google Chrome to do a javascript redirect WITH history?
Thanks.
Explanation We have a table of items, when clicking on the row, I want the page to navigate to a specified URL, if anyone has a good solution to this other than using the onclick=send method we are using now, please let me know.
Update It appears that Stackoverflow its-self has this exact same issue. In the main view, click on one of the first 3 columns in the question list (# answers, etc..), then click the back button, it will take you back 2 pages.
To redirect to a new URL or page, you assign the new URL to the location. href property or use the location. assign() method.
Answer: Use the JavaScript window. location Property If you want to redirect the user from one page to another automatically, you can use the syntax window. location. replace("page_url") .
A JavaScript redirect is a piece of JavaScript code that is used to automatically transfer a visitor from a landing page to a different target page.
I know this is an older question, but if you're navigating to a link on the same page, you should be able to simply do the following, where 123 is the item id:
window.location = "items/123";
Although, I first must say that this is Chrome behaving stupid, and you probably should not worry about it. Try to create a dummy form and with a GET method and programmatically submit it...
<form id="dummyForm" method="GET" action="#">
<input type="hidden" name="test" value="test" />
</form>
Then your onclick...
var frm = document.forms["dummyForm"];
frm.action = url;
frm.submit();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With