get the current domain name in js code example Example 1: get domain name javascript window.location.hostname Example 2: current url window.location.href