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

JavaScript06

如何通过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>

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

//获取域名

host = window.location.host

host2=document.domain

if(host!="xxx.com") alert("illegal")

<script type="text/javascript">

onload = function ()

{

    var locurl = window.location.host //获取当前页主域名

    var tiaozhuan = document.getElementById("tiaozhuan")

    if(locurl == 'C')

    {

        tiaozhuan.src='D'

    }

    else

    {

        tiaozhuan.src='B'

    }

}

</script>

<iframe id="tiaozhuan" src="B" scrolling="no" frameborder="0" marginwidth="0px" marginheight="0px"></iframe>