You are here: Reference > JavaScript > client-side > HTML DOM > properties > protocol (document, location, a, area, img)

protocol property (document, location, a, area, img)

Browser support:
Sets or retrieves the protocol component of the URL assigned to the object.
The protocol is a standard that specifies and controls the communication between computers.

Syntax:

object.protocol;
You can find the related objects in the Supported by objects section below.
This property is read/write.

Possible values:

String that specifies or retrieves the protocol component.
One of the following values:
file:
Protocol is a file protocol.
ftp:
File Transfer Protocol.
gopher:
A hierarchical hyperlinkable protocol.
http:
Hypertext Transfer Protocol.
https:
Secure Hypertext Transfer Protocol
javascript:
Executing JavaScript code.
mailto:
Opens the new mail dialog of the default e-mail client application, with the specified e-mail address.
news:
News Network Transfer Protocol.
nntp:
News Network Transfer Protocol.
prospero:
res:
telnet:
Telnet Remote Protocol
view-source:
wais:
Default: this property has no default value.

Example HTML code 1:

This example illustrates the use of the protocol property for an anchor:
<head>
    <script type="text/javascript">
        function AnalyzeTarget () {
            var anchor = document.getElementById ("myAnchor");

            var message = "";
            message += "hash: " + anchor.hash + "\n";
            message += "host: " + anchor.host + "\n";
            message += "hostname: " + anchor.hostname + "\n";
            message += "href: " + anchor.href + "\n";
            message += "pathname: " + anchor.pathname + "\n";
            message += "port: " + anchor.port + "\n";
            message += "protocol: " + anchor.protocol + "\n";
            message += "protocolLong: " + anchor.protocolLong + "\n";
            message += "search: " + anchor.search + "\n";

            alert (message);
        }
    </script>
</head>
<body>
    <a href="http://help.dottoro.com/test.php?id=2#bookmark" id="myAnchor">A sample anchor</a>
    <br /><br />
    <button onclick="AnalyzeTarget ();">Analyze the destination of the anchor above</button>
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content