A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

How to Get Portion of URL Path in JavaScript
Q:

How to Get Portion of URL Path in JavaScript

0

How to Get Portion of URL Path in JavaScript

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Use the window.location Object

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>

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now