Javascript examples for String Operation:String Search
Using Regex to find domain name without www
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=function(){//w w w .j a va 2 s . c om function getDomain(url) { var a, domain; a = document.createElement("a"); a.href = url; domain = a.hostname; domain = domain.replace(/^www\./, ""); return domain; } console.log(getDomain("http://www.gmail.com")); console.log(getDomain("https://gmail.com")); } </script> </head> <body> </body> </html>