jquery,domain,get URL [英] jquery, domain, get URL

查看:168
本文介绍了jquery,domain,get URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用jquery获取域名?

解决方案

您不需要jQuery,因为简单的javascript就足够了:

  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);  / pre> 



有关进一步的域相关值,请查看 window.location 在线。您可能会发现 location.host 是一个更好的选择,因为其内容可能与 document.domain 不同。例如,url http://192.168.1.80:8080 将在 document.domain 中只有ipaddress,但是在 location.host 中的ipaddress和端口号。


How can I get the domain name with jquery ??

解决方案

You don't need jQuery for this, as simple javascript will suffice:

alert(document.domain);

See it in action:

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);

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,domain,get URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆