问题描述
如何用jquery获取域名??
How can I get the domain name with jquery ??
推荐答案
你不需要 jQuery,因为简单的 javascript 就足够了:
You don't need jQuery for this, as simple javascript will suffice:
alert(document.domain);
查看实际操作:
console.log("Output;");
console.log(location.hostname);
console.log(document.domain);
alert(window.location.hostname)
console.log("document.URL : "+document.URL);
console.log("document.location.href : "+document.location.href);
console.log("document.location.origin : "+document.location.origin);
console.log("document.location.hostname : "+document.location.hostname);
console.log("document.location.host : "+document.location.host);
console.log("document.location.pathname : "+document.location.pathname);
有关域相关的更多值,请查看window.location 的属性
在线.您可能会发现 location.host
是更好的选择,因为它的内容可能与 document.domain
不同.例如,url http://192.168.1.80:8080
将只有 document.domain
中的 ipaddress,但 location 中的 ipaddress 和端口号.host
.
For further domain-related values, check out the properties of window.location
online. You may find that location.host
is a better option, as its content could differ from document.domain
. For instance, the url http://192.168.1.80:8080
will have only the ipaddress in document.domain
, but both the ipaddress and port number in location.host
.
这篇关于jquery,域,获取 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!