John Brunner
John Brunner

Reputation: 2872

Change URL parameter without redirecting to new URL

I want to know how it is possible to change the URL parameter without a redirection. For example the user clicks on "page 2" which is implemented with pagination, the data is retrieved via ajax, but I want to provide a URL to the user so he could send that page2 with the same results to a friend or whatever.

Searching the web and stackoverflow everyone states that this is NOT possible, it is just possible to change the hash (parent.location.hash = "whatever value";).

But HOW is this done at Airbnb? When I search for a city, the URL of the result page is this:

https://www.airbnb.at/s/london

When I click on "page 2" of the pagination, the data is loaded via Ajax and the new URL is this (without redirection):

https://www.airbnb.at/s/london?page=2

How is that done?

Upvotes: 0

Views: 336

Answers (2)

Surya Peddada
Surya Peddada

Reputation: 265

I think this will helps you,Try this

 <a href="link1.php" rel="tab" class="link">link1</a> |
    <a href="link2.php" rel="tab" class="link">link2</a> |
    <a href="link3.php" rel="tab" class="link">link3</a>
    <script>
$(function(){
    $("a.link").on("click",function(e){
        e.preventDefault();// or return false; 
        window.history.pushState({path:this.href},'',this.href);
    });
 });
    </script>

Upvotes: 0

ignasi
ignasi

Reputation: 443

Probably with pushState from History API. You can read more about that at History API or Manipulating the browser history

Upvotes: 1

Related Questions