Reputation: 10364
This is the URL:
http:// localhost:8888/index.html.
How to get the port number from this URL using jQuery?
Upvotes: 0
Views: 7863
Reputation: 70169
It is available in the location
object:
location.port
Note that when no port is present in the URL, location.port
will return an empty string.
If you need to get the port even when the implicit default port is used, try:
var port = location.port || (location.protocol === 'https:' ? '443' : '80');
This should suffice for pages served through http
and https
protocols.
Upvotes: 9