Murat Çorlu
Murat Çorlu

Reputation: 8545

How can I change URL without refreshing page like Google+?

When I was examining Google+, I'm surprized when I see usage of URLs. Google profile URLs change without refresing page. For example this is a photos tab URL: https://plus.google.com/104560124403688998123/photos When you click Videos tab, URL exactly goes to https://plus.google.com/104560124403688998123/videos without refreshing page. How Google coders success this?

Upvotes: 6

Views: 4431

Answers (4)

Kiran Baste
Kiran Baste

Reputation: 1

You could try using a pushState. You can change the URL to another URL within the same domain, but can not change the domain for security reasons.In Javascript, you can use.

window.history.pushState(“object or string”, “Title”, “/new-url”);

Object and string is your domain ex. www.google.co.in title you can give whats you want. and lastly you place new url ex. 'webhp?source=search_app'

ex. window.history.pushState(“www.google.co.in”, “Google”, “/webhp?source=search_app”);

Upvotes: 0

atilkan
atilkan

Reputation: 5018

This is about HTML 5. take a look at "onpopstate event". For further information go to the link. http://spoiledmilk.dk/blog/html5-changing-the-browser-url-without-refreshing-page

Upvotes: 1

Andreas Jansson
Andreas Jansson

Reputation: 3297

Have a look at the history object https://developer.mozilla.org/en/DOM/Manipulating_the_browser_history

Especially history.pushState and history.replaceState

(Should mention that this only works in modern browsers, for old ones use hashes).

Upvotes: 7

apscience
apscience

Reputation: 7243

You could try using a hash. This is not how google does it, but it doesn't force a refresh. In Javascript, you can use

parent.location.hash = "Text";

so that the URL will be http://yoursite.com/yourpage#text

Edit: This seems to be new to Google+. GMail uses a hash like

https://mail.google.com/mail/u/1/#inbox/130f48da33c5330

Upvotes: -1

Related Questions