The DOM Location Object Properties - Following Protocol
(Page 6 of 6 )
The protocol object returns or sets which protocol the present URL is using. An example of a protocol would be HTTP or FTP. Here we will say that our URL is http://www.devshed.com/. Here is the code:
<html>
<body>
<script type="text/javascript">
alert(location.protocol);
</script>
</body>
</html>
This will result in an alert box containing the following text:
http:
And just as with the others, we can create the result in a window instead of a pop-up, like so:
<html>
<body>
<script type="text/javascript">
document.write("This URL uses the following protocol: ");
document.write(location.protocol);
</script>
</body>
</html>
Giving us:
This URL uses the following protocol: http:
Search Me
You have probably seen URLs that seem to be asking a lot of questions on the web. We can extract the data after the question mark (?) using the search object. For instance, if you wanted to retrieve stock data about Microsoft off of Yahoo Finance, this is the URL you would be directed to: http://finance.yahoo.com/q?s=msft. Let's assume that we are going to use search on this URL. Here is the program:
<html>
<body>
<script type="text/javascript">
alert(location.search);
</script>
</body>
</html>
This would create a pop-up with the following data in it:
?s=msft
Conclusion
Well that gives us a basic overview of all the Location Object Properties. In our next article we will cover the three Location Object Methods. There are only three, and so as a bonus we will also begin a discussion of the History Objects as well. The History Objects let us work with the user's history data, giving us the ability to allow them to move back and forth among recently-visited URLs. It's a simple yet powerful tool, so make sure you check back in frequently. Thanks for reading.
Till then...
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |