3 Responses to “How To Get The Domain From A URL Using JavaScript”

This page contains comments from the How To Get The Domain From A URL Using JavaScript article.

  1. Just a quick note, you might want to take into consideration ‘https’, for example, https://twitter.com returns https when you use the “Extract” above.

    Otherwise, I like it.

  2. Bob says:

    It breaks if using protocol agnostic uri:

    //ajax.googleapis.com

    Thanks for sharing!

  3. rox says:

    Nice script .. but what should i do if i want only the base domain name .. like i want google.com only from http://mail.google.com .

Leave a Reply

Anti-Spam Quiz:


Stephen Cronin

is Manager of Online Service Delivery at a Queensland Government department & has been a freelance WordPress developer/consultant since 2007
*Content on this site is my own and is not related to my employer

Hire me - I'm expensive, but I'm very good!

WordPress Plugins

Want a Custom WordPress plugin? See my Services page.

Greasemonkey Scripts

Visit my home page at Userscripts.org.