How to get domain/sub-domain/extension from URL in javascript? 2013

View previous topic View next topic Go down

How to get domain/sub-domain/extension from URL in javascript? 2013

Post by Admin on Sun Sep 15, 2013 4:03 am

2013 2013 2013 <div dir="ltr" style="text-align: left;" trbidi="on">Consider the following URL:</br>http://www.google.com/</br> This URL has 3 parts</br></br>1) www - subdomain</br>2) google - domain</br>3) com - extension</br></br> In javascript, use the below code to get the complete URL <pre style="font-family:arial;font-size:12px;border:1px solid #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;;padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;">document.domain<br />var tokens = document.domain.split('.');//[www,google,com]<br />var subdomain = tokens[tokens.length - 3];//www<br />var domain = tokens[tokens.length - 2];//google<br />var extension = tokens[tokens.length - 1];//com<br /><br /></code></pre></br></div><br> 2013 2013 2013 <br><div dir="ltr" style="text-align: left;" trbidi="on">Consider the following URL:</br>http://www.google.com/</br> This URL has 3 parts</br></br>1) www - subdomain</br>2) google - domain</br>3) com - extension</br></br> In javascript, use the below code to get the complete URL <pre style="font-family:arial;font-size:12px;border:1px solid #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;;padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;">document.domain<br />var tokens = document.domain.split('.');//[www,google,com]<br />var subdomain = tokens[tokens.length - 3];//www<br />var domain = tokens[tokens.length - 2];//google<br />var extension = tokens[tokens.length - 1];//com<br /><br /></code></pre></br></div><br>2013 2013 2013 <br> <a href="http://www.matrixar.com/" title="Matrix ">المصفوفة : أجمل الخلفيات والصور</a>

Admin
Admin

Posts : 64122
Join date : 2013-02-22

View user profile http://prowebsites1.forumaroc.net

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum