Javascript Browser Window alert() Method show current URL

Introduction

Alert the hostname of the current URL:

alert(location.hostname);

Click the button to alert the hostname of the current URL.

View in separate window

<!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>



PreviousNext

Related