Alert the hostname of the current URL:
alert(location.hostname);
Click the button to alert the hostname of the current URL.
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <script> function myFunction() {//w w w . jav a2 s. com alert(location.hostname); } </script> </body> </html>