如何通过js获取当前访问页面的域名

JavaScript012

如何通过js获取当前访问页面的域名,第1张

<input type="text" style=" width:300px" name="new" id=new">

<script>

var nurl = document.referrer//来源url

document.URL  //获取当前域名

   document.title//获取当前页面标题

document.getElementById('new').innerHTML = nurl</script>

我是爱分享资源网的站长,如果你觉得不错请访问下我的网站,谢谢了!

<!DOCTYPE html>

<html>

<head>

<title>子窗口</title>

<script type="text/javascript">

document.write(window.parent.document.URL)

</script>

</head>

<body>

</body>

</html> <!DOCTYPE html>

<html>

<head>

<title>父窗口</title>

</head>

<body>

<-- 需要与子窗口保持在同一目录下,或修改此处连接地址 -->

<iframe src="child.html" style="width:500pxheight:500px"></iframe>

</body>

</html>

这个需要在IE中查看,如果要用谷歌浏览器,需要部署到服务器上。

今天给各位朋友介绍两种js获取当前域名

代码如下

//获取当前域名

1、window.location.host

2、document.domain

//获取当前页面地址

url

=

window.location.href

例子

代码如下

<script

language="javascript">

//获取域名

host

=

window.location.host

host2=document.domain

//获取页面完整地址

url

=

window.location.href

document.write("<br>host="+host)

document.write("<br>host2="+host2)

document.write("<br>url="+ur(www.45it.net)l)

</script>

补充:

获取当前域名信息

代码如下

thisTLoc

=

top.location.href

thisPLoc

=

parent.document.location

thisTHost

=

top.location.hostname

thisHost

=

location.hostname

strwrite

=

thisTLoc:

["

+

thisTLoc

+

"]”

strwrite

+=

thisPLoc:

["

+

thisPLoc

+

"]”

strwrite

+=

thisTHost:

["

+

thisTHost

+

"]”

strwrite

+=

thisHost:

["

+

thisHost

+

"]”

document.write(

strwrite

)