Skip to main content

JavaScript location.host vs location.hostname

By Sam Deering

JavaScript

Share:

Free JavaScript Book!

Write powerful, clean and maintainable JavaScript.

RRP $11.95

JavaScript location.host vs location.hostname example for this domain address https://jquery4u.com

location.host gives us jquery4u.com
location.hostname gives us jquery4u.com

You may be wondering, whats the difference?

Well host takes into consideration any specific ports also!

ports

Try it below!

Check out this awesome site below.

source:
https://bl.ocks.org/abernier/raw/3070589/

Sam Deering has 15+ years of programming and website development experience. He was a website consultant at Console, ABC News, Flight Centre, Sapient Nitro, and the QLD Government and runs a tech blog with over 1 million views per month. Currently, Sam is the Founder of Crypto News, Australia.

New books out now!

Get practical advice to start your career in programming!


Master complex transitions, transformations and animations in CSS!