How to get hostname & related details in Javascript

The following set of codes can be used to get the host related details in a javascript function.

window.location.host : you'll get sub.domain.com:8080 or sub.domain.com:80
window.location.hostname : you'll get sub.domain.com
window.location.protocol : you'll get http:
window.location.port : you'll get 8080 or 80
window.location.origin : you'll get http://sub.domain.com

Cheers.

1 Comment on "How to get hostname & related details in Javascript"

Leave a Reply

Your email address will not be published. Required fields are marked *