Get domain name, URL and file path-name use JavaScript
JavaScript: get the domain name of a website using JavaScript. Use document.location() and get application hostname, URL and open file path to clear.
This tutorial I will help you how to access our web page domain name, URL, and path in a variable and alert these variables in your project. You can follow the example and copy the source code and apply in your project.
When you work on a web page, then sometimes you need to print hostname or URL. That time it will help you to solve this. And you can display the original file path, which is using current page.
Display domain name:
<script> var domain_name=document.location.hostname; alert(domain_name); </script>
if you need to web page URL path so you can access web URL path use this example. Follow the example:
Display web URL:
<script> var url=document.URL; alert(url); </script>
if you need to web page current file path, which file is open in the browser and user work in current page so you need to follow this example:
Display current file path:
<script> var file_path= document.location.pathname; alert(file_path); </script>