
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
Difference between window.location.href, window.location.replace and window.location.assign in JavaScript?
The window object includes the location object in JavaScript. It includes the following properties −
window.location.href
It returns the URL of the current page.
Example
<!DOCTYPE html> <html> <body> <p>Click below to get the complete URL of the page.</p> <button onclick = "display()">URL</button> <script> function display() { var res = location.href; document.write(res); } </script> </body> </html>
window.location.replace
It is used to replace the current document.
Example
<!DOCTYPE html> <html> <body> <button onclick = "display()">Replace current document</button> <script> function display() { location.replace("https://www.qries.com") } </script> </body> </html>
window.location.assign
If you want to load a new document, use JavaScript assign.
Example
<!DOCTYPE html> <html> <body> <button onclick = "display()">Open new document</button> <script> function display() { location.assign("https://www.qries.com") } </script> </body> </html>
- Related Articles
- HTML Location assign( ) Method
- HTML DOM Location href Property
- HTML DOM Location replace() method
- JavaScript Location protocol Property
- Location protocol Property in JavaScript.
- How to use Push-Location and Pop-Location command in PowerShell?
- JavaScript BOM Window Screen
- Min window substring in JavaScript
- Difference between Stop and Wait protocol and Sliding Window protocol
- How to set location and location.href using JavaScript?
- Window innerWidth and innerHeight Properties in JavaScript.
- How to use Location API in Android to track your current location?
- How to copy items from one location to another location using PowerShell?
- How to use Location API in Android to track your current location using Kotlin?
- Finding median for every window in JavaScript
- 8085 program to move blocks of bits from source location to a destination location

Advertisements