0

What I need is for a webpage to completely alter the users adressbar on visit.

For instance: I visit www.X.com, but my adress bar displays www.Z.com.

I have already looked at history.pushState / history.replaceState, but using them I get results like this: www.X.com/www.Z.com.

Is there a way, preferably using history.pushState/replaceState, to accomplish this effect?

halfer
  • 19,824
  • 17
  • 99
  • 186
Robert Kraaijeveld
  • 687
  • 1
  • 6
  • 14

2 Answers2

0
function changeUrl(page, url) {
    if (typeof (history.pushState) != "undefined") {
        var obj = { Page: page, Url: url };
        history.pushState(obj, obj.Page, obj.Url);
    } else {
        alert("Browser does not support HTML5.");
    }
}
$(function () {
    $("#button1").click(function () {
        changeUrl('Page1', 'Page1.htm');
    });
    $("#button2").click(function () {
        changeUrl('Page2', 'Page2.htm');
    });
    $("#button3").click(function () {
        changeUrl('Page3', 'Page3.htm');
    });
});
entio
  • 3,816
  • 1
  • 24
  • 39
  • It would be nice to explain what the code does instead of just placing a piece of code. – entio Feb 25 '16 at 10:35
-2

I fixed the issue with my hosting provider.

halfer
  • 19,824
  • 17
  • 99
  • 186
Robert Kraaijeveld
  • 687
  • 1
  • 6
  • 14
  • 2
    This is not an answer to the question. The actual answer to the question is that it is not possible, for security reasons, to alter the hostname in the browser bar without reloading the page. – Chris Lear Feb 25 '16 at 10:36