//当前页面绝对路径地址
var curRequestPath = window.document.location.href;
//当前页面相对路径地址
var pathName = window.document.location.pathname;//相对路径在绝对路径中的索引
var ipAndPort = curRequestPath.indexOf(pathName);//获取ip及port
var localhostPath = curRequestPath.substring(0,ipAndPort);//项目名称
var projectName = pathName.substring(0,pathName.substr(1).indexOf('/')+1);//导出文件的绝对路径
var aa = localhostPath + projectName + '/filedown/' + file_name + '.xls';
//保存文件
window.location.href = aa;
欢迎大家及时指正。
这段博客代码使用JavaScript实现获取当前页面的绝对路径、相对路径,进而获取IP及端口、项目名称,最终拼接出导出文件的绝对路径,并通过设置window.location.href实现文件保存。

2366

被折叠的 条评论
为什么被折叠?



