I'm using window.location.href to redirect my browser and I am not sure why one works and one doesn't. When I use a relative link, it refreshes the current page. When I use the full url it redirects. The page I'm on and the Process.aspx page are on the same directory level. So I should just be able to have a relative link? When I do that though it just reloads the current page I'm on. What basic idea am I missing about window.location.href?
$(document).ready(function() {
$( "button" )
.button();
$("#cancel")
.click(function( event ) {
alert("click");
//Below Line Doesn't work
window.location.href = "/Process.aspx";
//Below Line Does work
window.location.href = "http://localhost:65215/Process.aspx";
});
});
From the Mozilla Developer Network documentation, href is the entire URL of the page. The only relative property in that list is path, which is relative to the host or the domain of the page.
You may also want to look at using the reload or replace method. See How to redirect to another webpage in JavaScript/jQuery?
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