<!DOCTYPE html>
<html>
<body>

<p>Click the button to alert the hostname of the current URL.</p>

<button onclick="myFunction()">Try it</button>

<script>
function myFunction() {
    alert(location.hostname);
}
</script>

</body>
</html>