Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

window.location.replace() not working to redirect browser

I make navigation with pages but this code not work, what's the problem ?

<script>
$(document).ready(function() {
$("body").keydown(function(event) {
  if(event.keyCode == 37) { // left
    window.location.replace("http://newsii.abudayah.com/photo/2)";  }
  else if(event.keyCode == 39) { // right
    window.location.replace("http://newsii.abudayah.com/photo/31)";  }
});
});
</script>
like image 986
Abudayah Avatar asked Jan 17 '12 17:01

Abudayah


People also ask

What is the difference between location assign () and location replace ()?

The replace() method of the Location interface replaces the current resource with the one at the provided URL. The difference from the assign() method is that after using replace() the current page will not be saved in session History , meaning the user won't be able to use the back button to navigate to it.

What does Window location replace do?

Window location. The replace() method replaces the current document with a new one.


1 Answers

Don't use .replace() for this, just assign the value directly.

Example

$("body").keydown(function(event) {

    if(event.keyCode == 37) { // left
        window.location = "http://newsii.abudayah.com/photo/2";
    }
    else if(event.keyCode == 39) { // right
        window.location = "http://newsii.abudayah.com/photo/31"; 
    }

});
like image 170
jondavidjohn Avatar answered Oct 13 '22 10:10

jondavidjohn