How To Get Host Ip And Port Number On Which The Application Is Running Using Javascript
Solution 1:
I'm afraid it's not possible to directly obtain the IP address via Javascript. It's not exposed in the window.location object.
Part of the reason for that is that subsequently accessing address:port is not semantically the same as accessing hostname:port - they are technically different URLs.
If what you're actually after is the host portion of the URL from which the current webapp was downloaded, you need:
window.location.hostnamewindow.location.portThe latter could be blank if the "default" port is being used, so you would also need to read:
window.location.protocoland check whether it's http: (i.e. port 80) or https: (port 443).
You can also use:
window.location.hostwhich will contain both the hostname and the port as colon-separated strings, with the same caveat as above that the :port section will be omitted if the content was accessed via the "default" port for the protocol.
Solution 2:
document.location.host// localhost:1234document.location.hostname// localhostdocument.location.port// 1234
Post a Comment for "How To Get Host Ip And Port Number On Which The Application Is Running Using Javascript"