我想从文件链接(http://www.example.com/file.exe
或https://example.com/folder/file.txt#someValue?params
)获得没有http(s)://www.
的纯文本域(例如,脚本的结果为example.com
)。使用Javascript或jQuery获取文件服务器域名
我如何使用js或jquery做到这一点?
我想从文件链接(http://www.example.com/file.exe
或https://example.com/folder/file.txt#someValue?params
)获得没有http(s)://www.
的纯文本域(例如,脚本的结果为example.com
)。使用Javascript或jQuery获取文件服务器域名
我如何使用js或jquery做到这一点?
这可以用纯javascript完成。
var url = new URL("https://example.com/folder/file.txt#someshit?someothershit");
var hostname = url.hostname.replace("www.", "");
console.log(hostname);
您可以使用URL()
构造,.hostname
财产,与空字符串
var url = new URL("http://www.example.com/file.exe")
.hostname.replace(/www\./, "");
console.log(url);
注意,' “WWW。” 代替
"www."
'是的一部分'.hostname' – guest271314