Broad Network


URL DOM Document Object Properties

DOM Document Object – Part 2

Forward: In this part of the series, we look at URL DOM Document Object Properties.

By: Chrysanthus Date Published: 31 Jul 2012

Introduction

This is part 2 of my series, DOM Document Object. In this part of the series, we look at URL DOM Document Object Properties. I assume, you have read the previous part of the series; this is a continuation.

Note: If you cannot see the code or if you think anything is missing (broken link, image absent, etc.), just contact me at forchatrans@yahoo.com. That is, contact me for the slightest problem you have about what you are reading.

The domain Property
When you type a URL of a web page at the address bar of the browser and click Go, the domain property can be used in the resulting web page to show the domain of the server that houses the web page. If the server were a personal web server, then the domain name would be something like, localhost. If the URL were, www.yahoo.com/page.htm, then the domain name would be something like, yahoo.com. Read and try the following code with a personal web server or a real server on the Internet:

<!DOCTYPE HTML>
<html>
<head>
    <title>Illustration</title>
</head>
<body>

    <p>elements elements elements</p>

    <script type="text/ECMAScript">
        alert(document.domain);
    </script>

</body>
</html>

The URL Property
The URL property returns the full URL of the current document. The current document is the document displayed on the screen. If the displayed web page has just one document, then the URL property returns the full URL of the displayed (current) web page. If the web page is a frameset, then the URL is not that of the frameset since a frameset has several documents, each in its own frame.

Read and try the following code, where there is one document in the web page:

<!DOCTYPE HTML>
<html>
<head>
    <title>Illustration</title>
</head>
<body>


    <script type = "text/ECMAScript">
        alert(document.URL);
    </script>

</body>
</html>

The referrer Property
The referrer property returns the URL of the document that loaded the current document. Imagine that you have a document displayed and the document has a hyperlink. If you click the hyperlink a new page will appear. The new page can display the URL of the former page using the following referrer property:

    document.referrer

Let us demonstrate this. Save the following code in a directory in a server (personal web server):

<!DOCTYPE HTML>
<html>
<head>
    <title>Illustration</title>
</head>
<body>

    <a href="page1.htm">Click Here</a>

</body>
</html>

Save the following code in the same directory with the name page1.htm:

<!DOCTYPE HTML>
<html>
<head>
    <title>Illustration</title>
</head>
<body>

    <script type = "text/ECMAScript">
        alert(document.referrer);
    </script>

</body>
</html>

Open the first document in a browser and click the hyperlink there. The alert box of the second document should display the URL of the first document.

That is it for this part of the series. We stop here and continue in the next part.

Chrys

Related Links

Major in Website Design
Web Development Course
HTML Course
CSS Course
ECMAScript Course
NEXT

Comments

Become the Writer's Fan
Send the Writer a Message