How to Get Portion of URL Path in JavaScript
window.location
You can use the built-in window.location object to retrieve the different part or portion of URL path in JavaScript, as demonstrated in the following example:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Get Portion of a URL in JavaScript</title> </head> <body> <script> document.write(window.location.href + "<hr>"); document.write(window.location.protocol + "<hr>"); document.write(window.location.host + "<hr>"); document.write(window.location.hostname + "<hr>"); document.write(window.location.port + "<hr>"); document.write(window.location.pathname + "<hr>"); document.write(window.location.search + "<hr>"); document.write(window.location.hash); </script> </body> </html>
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Use the
window.location
ObjectYou can use the built-in
need an explanation for this answer? contact us directly to get an explanation for this answerwindow.location
object to retrieve the different part or portion of URL path in JavaScript, as demonstrated in the following example: