How to Display Changed Browser URL Without Reloading Through alert using JavaScript ? Last Updated : 24 Jan, 2023 Comments Improve Suggest changes Like Article Like Report To change the URL in the browser without loading the new page, we can use history.pushState() method and replaceState() method from JavaScript. To display the browser-URL before changing the URL we will use window.location.href in the alert() function and will use again after changing the browsers-URL. Note: The history.pushState() method combines HTML 5 History and JavaScript pushState() method. Syntax: alert(" Message:" + window.location.hrf); Below examples illustrate the above approach: Example 1: HTML <head> <script> function geeks() { alert("The current URL of this" + " page is: " + window.location.href); } function change_url() { window.history.pushState("stateObj", "new page", "changedURL.html"); alert("The URL of this page is: " + window.location.href); } </script> </head> <body onload="geeks()"> <a href="javascript:change_url()"> Click to change url </a> </body> Output: Example 2: HTML <head> <script type="text/javascript"> function geeks() { alert("The current URL of this " + "page is: " + window.location.href); } function change_url() { window.history.replaceState("stateObj", "new page", "changedURL.html"); alert("The URL of this page is: " + window.location.href); } </script> </head> <body onload="geeks()"> <a href="javascript:change_url()"> Click to change url </a> </body> Output: Comment More infoAdvertise with us Next Article How to Display Changed Browser URL Without Reloading Through alert using JavaScript ? V VijayanathanJayaprakash Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Questions Similar Reads How to display warning before leaving the web page with unsaved changes using JavaScript ? To display a warning before leaving a web page with unsaved changes, you can use the beforeunload event in JavaScript. Syntax:// Event listener for the 'beforeunload' eventwindow.addEventListener('beforeunload', function (e) { // Check if any of the input fields are filled if (fname !== '' || lname 3 min read How to modify URL without reloading the page using JavaScript ? In this article, we are going to see how to modify URL without reloading the page using JavaScript Below are the methods to modify the URL without reloading the page using JavaScript: Table of Content Replacing the current state with replaceState() MethodAdding a new state with pushState() MethodMet 3 min read How to reload CSS without reloading the page using JavaScript ? While working with CSS, you might have come across situations where you made some changes in the stylesheet and had to do a hard reload to see the changes reflected in your browser. Or maybe the style depends on some user interaction and you don't wish to hard reload the page every time. Sometimes y 2 min read How to redirect browser window back using JavaScript ? Redirecting a browser window back to the previous page using JavaScript is a common task for web developers looking to enhance user navigation. This guide will cover the simple yet important methods available in JavaScript to achieve this functionality, ensuring a smooth user experience. There are s 2 min read How to get the new image URL after refreshing the image using JavaScript ? The browser cache relies on the image URL to decide whether the image is the same or not and whether to use the stored version. It means if we change something within the URL and then attempt to reload the image, the cache will no longer be able to change that it is the same resource. The cache will 2 min read How to Extract the Host Name from URL using JavaScript? Extracting the hostname from a URL using JavaScript means retrieving the domain part from a complete web address. This can be done using JavaScript's URL object or methods like window.location, which allow easy access to the hostname of a URL.What is URL?A URL (Uniform Resource Locator) is the web a 2 min read How to detect the user browser ( Safari, Chrome, IE, Firefox and Opera ) using JavaScript ? The browser on which the current page is opening can be checked using JavaScript. The userAgent property of the navigator object is used to return the user-agent header string sent by the browser. This user-agent string contains information about the browser by including certain keywords that may be 4 min read How to Get Browser to Navigate URL in JavaScript? As a web developer, you may need to navigate to a specific URL from your JavaScript code. This can be done by accessing the browser's window object and using one of the available methods for changing the current URL.In JavaScript, there are several approaches for navigating to a URL. The most common 4 min read How to change the href value of a tag after click on button using JavaScript ? JavaScript is a high-level, interpreted, dynamically typed, and client-side scripting language. HTML is used to create static web pages. JavaScript enables interactive web pages when used along with HTML and CSS. Document Object Manipulation (DOM) is a programming interface for HTML and XML document 4 min read How to make browser to go back to previous page using JavaScript ? There are two popular methods to navigate a browser back to the previous page. These methods allow easy navigation in a web session's history, offering simple and effective ways to move backward or forward through a user's browsing history.These are the following two ways: Table of ContentUsing hist 3 min read Like