CancelImage Upload

How to load a document's current domain name using JavaScript

If you are working on a multi domain platform you may need to find out through which name the website is being accessed. In JavaScript this task can be accomplished via the following code:

var domainName = document.domain;

Note that the domain is returned without "http://" preceding it. For a more insightful example see the following code:

<html>
<head>
<title>Returning Domain Name in JavaScript</title>
<script type="text/javascript">

function loadDomain()
{

        var display = document.getElementById("display");

        display.innerHTML = document.domain;

}

</script>

</head>
<body onload="javascript:loadDomain();">

<span id="display"></span>

</body>
</html>


Login
Want to leave a comment?

No problem. Just enter your email and password below.


register | home | reminder

myDesignTool Networking • www.mydesigntool.cominfo@mydesigntool.com