How To Get Default Port Number On Which Web Application Is Running (or Deployed) Using Javascript
I have a web application which is deployed at some port say 8085, and hostname is sample.something.com. Using window.location.host or window.location.port, the port is coming as bl
Solution 1:
If window.location.port
is empty that means the application is running on port 80 for http and 443 for https.
As mentioned in a comment, you can use window.location.protocol
to check what protocol is used (http or https).
Implementation:
function getPort(){
if(location.port != ''){
return location.port;
}
elseif(location.protocol== 'http'){
return80;
}
elseif(location.protocol== 'https'){
return443;
}
}
Post a Comment for "How To Get Default Port Number On Which Web Application Is Running (or Deployed) Using Javascript"