How to get base domain from the URL in JavaScript

后端 未结 9 552
萌比男神i
萌比男神i 2020-12-06 02:52

I would like to extract the base domain from the url in javascript. For example for the list of urls listed below I need to get google.com (or googl

9条回答
  •  星月不相逢
    2020-12-06 03:24

    (function (){
        var d = document.domain.split('.');
        var i = d.indexOf('google'); 
        return d.slice(i).join('.');
    })();
    

提交回复
热议问题