163邮箱官方注册入口,seo高级优化方法,网站开发地址,网站域名后缀有什么用一、js获取当前域名
1、方法一
var domain document.domain;2、方法二
var domain window.location.host;3、注意问题 由于获取到的当前域名不包括 http://#xff0c;所以把获取到的域名赋给 a 标签的 href 时#xff0c;别忘了加上 http://#xff0c;否则单击链…一、js获取当前域名
1、方法一
var domain document.domain;2、方法二
var domain window.location.host;3、注意问题 由于获取到的当前域名不包括 http://所以把获取到的域名赋给 a 标签的 href 时别忘了加上 http://否则单击链接时导航会出错。
二、实例
实例1 注意记得在对应路径下创建file.xls文件
!DOCTYPE html
html langen
headmeta charsetUTF-8titleDocument/titlescript srchttps://cdn.bootcss.com/jquery/2.0.0/jquery.min.js/scriptscript src//js.zapjs.com/js/download.js/scriptscriptfunction skip(){//获取当前域名var domain window.location.host;//跳转链接window.location.href http://domain;}function download_file(){//获取当前域名var domain document.domain;//下载文件window.location.href http://domain/file.xls;// download(http://domain/file.txt,file.txt,text/plain);}/script
/head
bodybutton onclickskip()跳转链接/buttonbr/button onclickdownload_file()下载文件/button!-- a hrefhttp://localhost/file.txt downloadfile.txt能下载txt文件(不能动态修改链接)/a --!-- a hrefjavascript:alert(测试弹出功能);测试/a --!-- a hrefjavascript:window.location http://document.domain/file.txt;不能下载txt文件/a --
/body
/html