Today I would like to introduce you two JS to get the current domain name
The code is as follows |
Copy Code |
Get the current domain name 1, Window.location.host; 2, Document.domain; Get current page address url = window.location.href; |
Example
The code is as follows |
Copy Code |
<script language= "JavaScript" > Get Domain Name host = Window.location.host; Host2=document.domain; Get full address of page url = window.location.href; document.write ("<br>host=" +host) document.write ("<br>host2=" +host2) document.write ("<br>url=" +url) </script> |
Add:
Get current domain name information
code is as follows |
copy code |
thistloc = Top.location.href; Thisploc = parent.document.location; Thisthost = top.location.hostname; Thishost = location.hostname; Strwrite = "Thistloc: [" + Thistloc + "]" Strwrite + = "Thisploc: [" + Thisploc + "]" Strwrite = "Thisthos T: ["+ Thisthost +"] " Strwrite =" Thishost: ["+ Thishost +]" document.write (strwrite); |