Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change window location Jquery

Tags:

I am using ajax to load my website content and want to update the window location when ajax is successful.

How can I update the window location to "/newpage"?? I need users to be able to go back and to refresh. Is this possible??

like image 708
user342391 Avatar asked Sep 08 '10 14:09

user342391


People also ask

What is window location href?

Window Location Href The window.location.href property returns the URL of the current page.

How do I change URL without reloading?

replaceState() method The replaceState() is another method that updates the URL without reloading the page. It works exactly the same way as pushState() , but replaces the existing browser history entry instead of adding a new one.


2 Answers

I'm assuming you're using jquery to make the AJAX call so you can do this pretty easily by putting the redirect in the success like so:

    $.ajax({
       url: 'ajax_location.html',
       success: function(data) {
          //this is the redirect
          document.location.href='/newpage/';
       }
    });
like image 58
Munzilla Avatar answered Oct 11 '22 16:10

Munzilla


You can set the value of document.location.href for this purpose. It points to the current URL. jQuery is not required to do this.

like image 25
jwueller Avatar answered Oct 11 '22 14:10

jwueller