Created
November 28, 2019 08:24
-
-
Save kevsersrca/102047323cdb4befa66dbfcb031f2e61 to your computer and use it in GitHub Desktop.
extract hostname
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function extractHostname(url) { | |
var hostname; | |
//find & remove protocol (http, ftp, etc.) and get hostname | |
if (url.indexOf("//") > -1) { | |
hostname = url.split('/')[2]; | |
} | |
else { | |
hostname = url.split('/')[0]; | |
} | |
//find & remove port number | |
hostname = hostname.split(':')[0]; | |
//find & remove "?" | |
hostname = hostname.split('?')[0]; | |
return hostname; | |
} |
Author
kevsersrca
commented
Nov 28, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment