Remove everything after domain and http in url javascript
This question already has an answer here:
You can try this:
//([^/,s]+.[^/,s]+?)(?=/|,|s|$|?|#)
Regex live here.
Live JavaScript sample:
var regex = ///([^/,s]+.[^/,s]+?)(?=/|,|s|$|?|#)/g;
var input = "https://www.google.com/hello/hi.php, http://youtube.com,"
+ "http://test.net#jump or http://google.com?q=test";
while (match = regex.exec(input)) {
document.write(match[1] + "<br/>");
};
使用全局的window.location.hostname
变量,它会给你这个信息。
上一篇: 使用JavaScript检测当前页面