
正文
js获取现在访问的域名,js获取当前页面的地址
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
如何用JavaScript获取当前页面的网址?
可以使用下列代码获取当前页面的网址:
window.location
// 或者
window.location.href
实例演示:
1、新建一个空白Html文档
2、输入javascript代码
script
alert(window.location.href)
/script
3、查看效果
相关问答
Q1: 如何通过js获取当前访问页面的域名
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
我是爱分享资源网的站长,如果你觉得不错请访问下我的网站,谢谢了!
Q2: 这段JS代码怎么修改才能获取来路域名
字符串处理下
strLength = document.referrer.length ;
strUrl = document.referrer.substring( 7 , strLength ) ;
strUrl = strUrl.substring( 0 , strUrl . indexOf("/") )
document.write( strUrl );
函数说明
str.Length -------------------返回字符串总长度
str.substring( start_Index, stop_Index ) -----------------截取指定区间字符串
str.indexOf( child_str ) -------------------------返回子字符串第一次在str中出现的位置的
Q3: JS如何限得当前根域名后跳转
通过document.domain拿到当前的域名
通过document.domain.split('.').slice(-2).join('.')获取一级域名
然后location.href=document.domain.split('.').slice(-2).join('.')即可
Q4: 火狐浏览器 js脚本求获取当前页面根域名的方法
您好!很高兴为您答疑!
您试下这个:
script language="javascript"
//获取域名
host = window.location.host;
host2=document.domain;
//获取页面完整地址
url = window.location.href;
document.write("brhost="+host)
document.write("brhost2="+host2)
document.write("brurl="+url)
/script
您可以在火狐社区了解更多内容。希望我的回答对您有所帮助,如有疑问,欢迎继续在本平台咨询。
Q5: 用JS获取当前域名并判断
//获取域名
host = window.location.host;
host2=document.domain;
if(host!="xxx.com") alert("illegal");
js获取现在访问的域名的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于js获取当前页面的地址、js获取现在访问的域名的信息别忘了在本站进行查找喔。







