通过微软官方接口预览office文件的js
//预览office
function office(url){
//文件名
filename = url;
var uri = url.replace("./","/");
uri = encodeURI(uri);
//获取协议
var protocol = window.location.protocol + '//';
//获取主机
var host = window.location.host;
//获取页面目录,通常是二级目录的情况下
var pathname = window.location.pathname;
pathname = pathname.replace("index.php","");
url = protocol + host + pathname + uri;
var apiurl = "https://view.officeapps.live.com/op/view.aspx?src=" + url;
layer.open({
title:filename,
type: 2,
area: ['80%', '80%'],
content: apiurl //这里content是一个普通的String
});
}

本文介绍了一个使用JavaScript函数预览Office文档的方法,通过调用微软官方API,能够在网页中直接打开并查看Word、Excel和PowerPoint等Office文件。
2322

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



