Show Output
<!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>