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?
How can I change the location of a page and not redirect the user?
290 Views Asked by AudioBubble AtThere are 6 best solutions below
                        
                            
                        
                        
                            On
                            
                                                    
                    
                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.
                        
                            
                        
                        
                            On
                            
                                                    
                    
                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.
                        
                            
                        
                        
                            On
                            
                                                    
                    
                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.
                        
                            
                        
                        
                            On
                            
                                                    
                    
                What you're asking for is called URL spoofing.
Any browser allowing this has a severe security issue.
You mean like, I'm visiting
http://www.fakebank.exampleand you want the address bar to displayhttp://www.yourbank.example? I think there are obvious reasons this won't be possible.