Eric Schmidt at Mobile World Congress

By: Google

220   16   42579

Uploaded on 03/01/2010

Eric Schmidt presents Google's vision of the mobile future at Mobile World Congress in Barcelona, Spain on Tuesday, February 16, 2010.
http://www.mobileworldcongress.com/

NOTE: This video has been updated to include an introductory video that played before Eric's speech.

Comments (2):

By anonymous    2017-09-20

Try:

function extractHostname(url) {
    var hostname;
    //find & remove protocol (http, ftp, etc.) and get hostname

    if (url.indexOf("://") > -1) {
        hostname = url.split('/')[2];
    }
    else {
        hostname = url.split('/')[0];
    }

    //find & remove port number
    hostname = hostname.split(':')[0];
    //find & remove "?"
    hostname = hostname.split('?')[0];

    return hostname;
}

document.write('Using "extractHostname":<br/>');
document.write(extractHostname("http://www.youtube.com/watch?v=ClkQA2Lb_iE") + "<br/>");
document.write(extractHostname("https://www.youtube.com/watch?v=ClkQA2Lb_iE") + "<br/>");
document.write(extractHostname("www.youtube.com/watch?v=ClkQA2Lb_iE") + "<br/>");
document.write(extractHostname("ftps://ftp.websitename.com/dir/file.txt") + "<br/>");
document.write(extractHostname("websitename.com:1234/dir/file.txt") + "<br/>");
document.write(extractHostname("ftps://websitename.com:1234/dir/file.txt") + "<br/>");
document.write(extractHostname("example.com?param=value") + "<br/>");
document.write('<br/>');

To address those who want the "root domain," use this function:

function extractRootDomain(url) {
    var domain = extractHostname(url),
        splitArr = domain.split('.'),
        arrLen = splitArr.length;

    //extracting the root domain here
    if (arrLen > 2) {
        domain = splitArr[arrLen - 2] + '.' + splitArr[arrLen - 1];
    }
    return domain;
}

document.write('Using "extractRootDomain":<br/>');
document.write(extractRootDomain("http://www.youtube.com/watch?v=ClkQA2Lb_iE") + "<br/>");
document.write(extractRootDomain("https://www.youtube.com/watch?v=ClkQA2Lb_iE") + "<br/>");
document.write(extractRootDomain("www.youtube.com/watch?v=ClkQA2Lb_iE") + "<br/>");
document.write(extractRootDomain("ftps://ftp.websitename.com/dir/file.txt") + "<br/>");
document.write(extractRootDomain("websitename.com:1234/dir/file.txt") + "<br/>");
document.write(extractRootDomain("ftps://websitename.com:1234/dir/file.txt") + "<br/>");
document.write(extractRootDomain("example.com?param=value") + "<br/>");

Yields:

Using "extractHostname":

www.youtube.com
www.youtube.com
www.youtube.com
ftp.websitename.com
websitename.com
websitename.com
example.com

Using "extractRootDomain":

youtube.com
youtube.com
youtube.com
websitename.com
websitename.com
websitename.com
example.com

Regardless having the protocol or even port number, you can extract the domain. This is a very simplified, non-regex solution, so I think this will do.

Note: If you try to use the "URL" object on input without a protocol (e.g. http, ftp, etc.), it will break.

*Thank you Timmerz, renoirb, rineez, BigDong, ra00l, and ILikeBeansTacos for your suggestions!

Original Thread

Popular Videos 0

SciChart High Performance Realtime Charts

Submit Your Video

If you have some great dev videos to share, please fill out this form.