最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

client side - How can I write something in browser's address bar with JavaScript after the page is completely loaded? -

programmeradmin0浏览0评论

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?

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?

Share Improve this question edited Jan 28, 2011 at 16:37 Douglas 37.8k9 gold badges79 silver badges91 bronze badges asked Jan 28, 2011 at 16:06 LostLordLostLord 2,32910 gold badges32 silver badges33 bronze badges 7
  • 6 Why would you need to do this? – Ben James Commented Jan 28, 2011 at 16:07
  • 3 Isn't possible, for obvious reasons. Browsers don't want their users going suicidal because they don't know your real web address. – goto-bus-stop Commented Jan 28, 2011 at 16:09
  • 6 THIS IS POSSIBLE. (But not the hostname, for obvious reasons.) ( stackoverflow.com/questions/4830361/… ) – Arnaud Le Blanc Commented Jan 28, 2011 at 16:14
  • 2 @Simon not only the hash – Arnaud Le Blanc Commented Jan 28, 2011 at 16:31
  • 1 This is possible, and can be put to good use: github.com/blog/760-the-tree-slider – Douglas Commented Jan 28, 2011 at 16:36
 |  Show 2 more comments

5 Answers 5

Reset to default 16

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

Maybe its already answered @ Change the URL in the browser without loading the new page using JavaScript .

You can set location.hash, but you can't replace the entire URI.

The reason this is not possible is it presents a security violation. This is why phishers write a gif file over where they believe the address bar will be.

My question is why would you want to do this? The only reason I can think of is you want to make someone think they are at http://Iamreallyyourbank.com when they are at http://IamStealingYourMoney.com, which is why the security is in place.

This is not possible. You cannot change the URL displayed in the browser. Not only would it be a horrible security practice, it would be a violation of trust to the people visiting your site.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论