In a web page URL, the
"www.example.com") is either the registered name or IP address assigned to a web page or website (can include a
port number as well).
port number of the current page?
Window interface has access to the
Location object that can be used via
Here's what the method looks like in practice:
This will return a string value containing the
hostname and, if the port value is non-empty, a
: symbol along with the port number of the URL.
Here are some example returned values to expect:
// Page URL: https://coderrocketfuel.com/courses window.location.host == "coderrocketfuel.com" // Page URL: https://coderrocketfuel.com:80/courses window.location.host == "coderrocketfuel.com:80" // Page URL: http://localhost:3000 window.location.host == "localhost:3000"
For more information on the browser support for this method, see its MDN web docs page.
Thanks for reading and happy coding!