How to get Domain name from URL using jquery..?

后端 未结 10 1033
一生所求
一生所求 2020-12-02 10:01

I have domain name for eq.

1) http://www.abc.com/search 
2) http://go.abc.com/work

I get only domain name from the above URL

Output

10条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-02 10:19

    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 more details click here window.location

    just append "http://" before domain name to get appropriate result.

提交回复
热议问题