使用Javascript或jQuery获取文件服务器域
我想从文件链接(使用Javascript或jQuery获取文件服务器域,javascript,jquery,Javascript,Jquery,我想从文件链接(http://www.example.com/file.exe或https://example.com/folder/file.txt#someValue?params) 如何使用js或jquery实现这一点?这可以通过普通javascript实现 var url=新url(“https://example.com/folder/file.txt#someshit?someothershit"); var hostname=url.hostname.replace(“www.,
http://www.example.com/file.exe
或https://example.com/folder/file.txt#someValue?params
)
如何使用js或jquery实现这一点?这可以通过普通javascript实现
var url=新url(“https://example.com/folder/file.txt#someshit?someothershit");
var hostname=url.hostname.replace(“www.,”);
log(主机名)
您可以使用URL()
构造函数,.hostname
属性,用空字符串替换“www.”
var url=新url(“http://www.example.com/file.exe")
.hostname.replace(/www\./,“”);
console.log(url)代码>注意,“www.”
是主机名的一部分