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

后端 未结 10 1034
一生所求
一生所求 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:11

    This worked for me.

    http://tech-blog.maddyzone.com/javascript/get-current-url-javascript-jquery

    $(location).attr('host');                        www.test.com:8082
    $(location).attr('hostname');                    www.test.com
    $(location).attr('port');                        8082
    $(location).attr('protocol');                    http:
    $(location).attr('pathname');                    index.php
    $(location).attr('href');                        http://www.test.com:8082/index.php#tab2
    $(location).attr('hash');                       #tab2
    $(location).attr('search');                     ?foo=123
    

提交回复
热议问题