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

后端 未结 10 1030
一生所求
一生所求 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-02 10:26

    While pure JavaScript is sufficient here, I still prefer the jQuery approach. After all, the ask was to get the hostname using jQuery.

    var hostName = $(location).attr('hostname');      // www.example.com
    

提交回复
热议问题