Thursday, November 19, 2009

Retrieve hostname & Port number in javascript

To retrieve the host name & Port number from a given URL use the below javascript code.

var url = remoteURL; //e.g http://mysite.proxy.com:8000/my/page.html
var nohttp = url.split('//')[1];
var hostPort = nohttp.split('/')[0];

if you run this script then for the above URL you will get the result as mysite.proxy.com:8000

No comments:

Post a Comment