Difference between "document.baseURI", "window.location.hostname", and "document.documentURI"? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Difference between "document.baseURI", "window.location.hostname", and "document.documentURI"?

www.w3schools.com/js/js_window_location.asp The window.location object can be used to get the current page address (URL) and to redirect the browser to a new page The window.location object can be written without the window prefix window.location.hostname returns the domain name of the web host The window.location.hostname property returns the name of the internet host (of the current page) document.baseURI Returns the absolute base URI of the document document.documentURI Returns the URI of the document

2nd Oct 2023, 8:40 PM
Katz321Juno
Katz321Juno - avatar
3 Answers
+ 4
🔹 window.location is a JavaScript object that tells you where you are on a webpage and can be used to take you to another webpage. For example, if you want to redirect the user to another page, you can use window.location.href = "https://www.example.com";. 🔹 window.location.hostname tells you the name of the website you are on. For example, if you are on the website “https://www.example.com”, window.location.hostname would return “www.example.com”. 🔹 document.baseURI and document.documentURI tell you where on that website you are. For example, if you are on the page “https://www.example.com/about.html” document.baseURI would return “https://www.example.com/” and document.documentURI would return “https://www.example.com/about.html”.
4th Oct 2023, 10:29 PM
Moree
Moree - avatar
+ 4
Anytime 😊. Yes, perhaps they have a valid reason. In any case, I wish you the best of luck and great success.
5th Oct 2023, 3:29 AM
Moree
Moree - avatar
+ 2
Moree thank you, w3schools didn't explain the differences that well
4th Oct 2023, 11:22 PM
Katz321Juno
Katz321Juno - avatar