0

Possible Duplicate:
Change the URL in the browser without loading the new page using JavaScript

i want just add url in address bar of browser Note: dont want redirect

e.i i have a url www.example.com/index.html

i want set url on 'address bar' like www.example.com/index/page2.html

i use document.location.hash = 'foo';

but it is add only # data like www.example.com/index.html#foo

note : i dont want to redirect only want to add url in address bar so don't answer document.location like that

any solution for that ?

Community
  • 1
  • 1
Tarun Baraiya
  • 506
  • 1
  • 9
  • 29
  • 2
    You can't do that, and it's for security reasons. – Pointy May 25 '12 at 14:08
  • http://stackoverflow.com/questions/6601609/how-to-manipulate-the-url-with-javascript-jquery – Ricardo Binns May 25 '12 at 14:10
  • 1
    Please check out the links posted here. Both describe how to do it. The security concerns restrict you from setting it to another url, but you can alter the path with the history API. – chucktator May 25 '12 at 14:22
  • @chucktator the best he could do is from his examplee is `www.example.com/index.html/page2.html` – JaredMcAteer May 25 '12 at 14:24
  • @JaredMcAteer Within your own domain you are allowed to change the path and filename portion of the url to anything you want. Facebook does it, Google does it and I've tried it out myself as well. – chucktator May 25 '12 at 14:25
  • 1
    it is possible see this blog and click any post title then it is change in address bar of browser see this http://freesubmiturlindia.blogspot.in – Tarun Baraiya May 26 '12 at 06:31

3 Answers3

2

Have a read here.

http://badassjs.com/post/840846392/location-hash-is-dead-long-live-html5-pushstate

Might help.

window.history.pushState('abc', "Title", "/new-url");
Tarun Baraiya
  • 506
  • 1
  • 9
  • 29
Grezzo
  • 2,132
  • 2
  • 20
  • 39
1

Can't be done. This is a security feature to make it harder to spoof a site (e.g. for phishing attacks)

Grezzo
  • 2,132
  • 2
  • 20
  • 39
0

I'm not sure if you can do this without using a redirect.

Here's a way to achieve your goal though.

Create page for www.example.com/index/page2.html that contains of a frame of www.example.com/index.html

In www.example.com/index.html redirect the user to www.example.com/index/page2.html if the www.example.com/index.html isn't inside a frame.

Larry Battle
  • 8,222
  • 4
  • 39
  • 54