A JavaScript Function for Turning URLs into Hostnames

April 12, 2008 @ 8:23 pm

I’ve been working on an Adobe AIR application that stores a password for use with connecting to a user’s specified server.  To do this, I use Adobe’s URLRequestDefaults object to manage the password.  In order to save a password into the object, though, I have to use the setLoginCredentialsForHost() method, which requires the hostname that the username and password will be saved for.  Unfortunately, though, the input from the user only gives me a URL to the server.  In order to use user’s provided input, I had to find a way to get the hostname out of the URL of the server provided by the user.

Read More »