Monday, July 10, 2017

Relative path Vs Absolute path in javascript

The path with reference to root directory is called absolute. The path with reference to current directory is called relative.

Relative Path

 Relative Path <img src="kitten.png"/>   

Absolute Path

 Absolute in all respects: <img src="http://www.foo.com/images/kitten.png">
Example of absolute paths:
  • D:\documents\something.doc
  • E:\music\good_music.mp3
<script>
 var full_path = location.protocol + "//" + window.location.host
</script>


For this page if you inspect the window.location object you will see
hash:       
host:       stackoverflow.com
hostname:   stackoverflow.com
href:       http://stackoverflow.com/questions/8401879/get-absolute-path-in-javascript
pathname:   /questions/8401879/get-absolute-path-in-javascript
port:       
protocol:   http:
search:     

No comments:

Post a Comment

Total Pageviews