austin cheney
austin cheney

Reputation:

How can I change the location of a page and not redirect the user?

I want to be able to change the address of a page but not issue any HTTP requests upon making that change. How can this be done using JavaScript?

Upvotes: 0

Views: 333

Answers (6)

user123444555621
user123444555621

Reputation: 152996

What you're asking for is called URL spoofing.

Any browser allowing this has a severe security issue.

Upvotes: 0

DisgruntledGoat
DisgruntledGoat

Reputation: 72530

To answer your question directly: it's impossible. You're asking how can you go to a different page without going to a different page, which is nonsense.

Although if a page is already in the browser cache (and a far future date has been set) then technically the user may be able to go to that page without requesting it again from your server. But you can't guarantee anything.

I think what you may be looking for is something like using frames. On example.com/index.html you can set up a full size frame and include a different page such as example.com/page2.html. Then any links within the frame won't change the URL listed in the browser. See this tutorial for info.

Upvotes: 0

Eli Grey
Eli Grey

Reputation: 35860

Do you not want to add a history entry? Just use location.replace(..).

Upvotes: 0

Gareth
Gareth

Reputation: 138062

You mean like, I'm visiting http://www.fakebank.example and you want the address bar to display http://www.yourbank.example? I think there are obvious reasons this won't be possible.

Upvotes: 11

Bungle
Bungle

Reputation: 19712

Assuming that you mean the address indicated in the browser's address bar, I don't believe that it can. Setting document.location or window.location will automatically trigger a page reload, as far as I know.

As olliej said, you can change the hash parameter (a.k.a. fragment identifier), which does not trigger a page reload.

Upvotes: 0

olliej
olliej

Reputation: 36783

You can set location.hash without a page load, but i'm not sure if that's what you're wanting -- your question is fairly vague.

Upvotes: 0

Related Questions