Javascript – How to write something in browser’s address bar with JavaScript after the page is completely loaded

client-sidejavascript

How can I write something ("hello my client" for example) in the browser's address bar with javascript after the page is completely loaded?

Mean writing something in address bar without entering – is it possible?

It seems we can do this job with JavaScript, if not can we do that with server side code?

Best Answer

How?

This is possible, but only the part after the hostname:

history.pushState(null, "page 2", '/foo.html');

Try this in your javascript console, this effectively changes the current path with /foo.html. (It's a new html5 feature, and is available in recent browsers only.)

See mozilla docs: https://developer.mozilla.org/en/DOM/Manipulating_the_browser_history#Adding_and_modifying_history_entries

Browser Compatibility

Why?

This is used to make ajax sites history/bookmark/link friendly by updating the URL as the content is updated. Currently most sites do this by only changing the hash part of the URL (e.g. Twitter with their #!.)

For instance Github uses this for their code browser: https://github.com/blog/760-the-tree-slider