Answers for "javascript get hostname from current url"

1

js get hostname from url

url = "http://www.example.com/path/to/somwhere";
urlParts = /^(?:\w+\:\/\/)?([^\/]+)([^\?]*)\??(.*)$/.exec(url);
hostname = urlParts[1]; // www.example.com
path = urlParts[2]; // /path/to/somwhere
Posted by: Guest on April-09-2021
0

javascript get hostname from current url

var host = window.location.protocol + "//" + window.location.host;
Posted by: Guest on April-07-2022

Code answers related to "javascript get hostname from current url"

Code answers related to "Javascript"

Browse Popular Code Answers by Language