views:

112

answers:

6

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?

A: 

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.

olliej
A: 

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.

Bungle
This may provide some more information: <http://answers.yahoo.com/question/index?qid=20070710175617AAEJX2C>
Bungle
+10  A: 

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.

Gareth
Yeah, thank goodness this isn't possible.
ceejayoz
A: 

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

Eli Grey
A: 

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.

DisgruntledGoat
Not exactly. I am asking how to make the DOM believe it is at one location when it is not really at that location at all. I don't want the page to go anywhere.
I don't get it, why do you want to do this?
DisgruntledGoat
A: 

What you're asking for is called URL spoofing.

Any browser allowing this has a severe security issue.

Pumbaa80