Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change the current URL?

Tags:

javascript

People also ask

How can I change my URL?

Navigate to the Settings tab. If the page has already been published, click the edit edit icon next to Page URL. In the dialog box, click Update to confirm that a redirect will be created from the page's previous URL to its new one. To change the domain of your page, click the Domain dropdown menu and select a domain.

How do I change URL without refresh?

history. pushState(nextState, nextTitle, nextURL); // This will replace the current entry in the browser's history, without reloading window.

How do I find my current URL?

Answer: Use the window. location. href Property location. href property to get the entire URL of the current page which includes host name, query string, fragment identifier, etc.


document.location.href = newUrl;

https://developer.mozilla.org/en-US/docs/Web/API/document.location


Simple assigning to window.location or window.location.href should be fine:

window.location = newUrl;

However, your new URL will cause the browser to load the new page, but it sounds like you'd like to modify the URL without leaving the current page. You have two options for this:

  1. Use the URL hash. For example, you can go from example.com to example.com#foo without loading a new page. You can simply set window.location.hash to make this easy. Then, you should listen to the HTML5 hashchange event, which will be fired when the user presses the back button. This is not supported in older versions of IE, but check out jQuery BBQ, which makes this work in all browsers.

  2. You could use HTML5 History to modify the path without reloading the page. This will allow you to change from example.com/foo to example.com/bar. Using this is easy:

    window.history.pushState("example.com/foo");

    When the user presses "back", you'll receive the window's popstate event, which you can easily listen to (jQuery):

    $(window).bind("popstate", function(e) { alert("location changed"); });

    Unfortunately, this is only supported in very modern browsers, like Chrome, Safari, and the Firefox 4 beta.


If you just want to update the relative path you can also do

window.location.pathname = '/relative-link'

"http://domain.com" -> "http://domain.com/relative-link"


Hmm, I would use

window.location = 'http://localhost/index.html#?options=go_here';

I'm not exactly sure if that is what you mean.