-
Notifications
You must be signed in to change notification settings - Fork 0
/
preview.html
executable file
·369 lines (336 loc) · 12.9 KB
/
preview.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Document</title>
<script src="static/js/lib/jquery-1.9.1.min.js"></script>
<script type="text/javascript">
var errorMsg;
$(function(){
$(".btndiv").hide();
var url_365 = GetQueryString("w365");//365预览方式
var url_ms = GetQueryString("wms");//微软预览方式
var preview_url = GetQueryString("prewurl");
var WOPISrc = GetQueryString("WOPISrc");
var fileName = GetQueryString("fileName",true);
if(fileName){
$("head title").html(decodeURI(fileName));
}
//errorMsg
errorMsg = GetQueryString("errorMsg");
var url365;
var urlms;
if(url_ms == null){
urlms = preview_url;
var access_token = GetQueryString("access_token");
if(access_token != undefined){
preview_url += "&access_token="+access_token;
}
preview_url = preview_url+"&WOPISrc="+WOPISrc;
$("#docViewer").attr("src",preview_url);
urlms = preview_url;
$("input[name='wms']").val(urlms);
url365 = url_365+"&fileName="+fileName;
if(url_365.indexOf("https")>-1){
url365 = url_365+"&ssl=1";
}
$("input[name='w365']").val(url365);
}
});
function GetQueryString(name,notunescape)
{
var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
var searchurl = window.atob(window.location.search.substr(1));
var r = searchurl.match(reg);
if(r!=null){
if(notunescape){
return r[2];
}else{
return unescape(r[2]);
}
}else{
return null;
}
}
$(document).ready(function(e){
var iframe = document.getElementById("docViewer");
if (iframe.attachEvent) {
iframe.attachEvent("onload", function() {
var docvalue = $($("#docViewer").get(0).contentWindow.document.body).find("#WACDialogText").html();
if(docvalue != undefined){
if(docvalue.indexOf("很抱歉,遇到问题,无法打开此演示文稿。请重试。")>-1){
$(".btndiv").show();
}
//很抱歉,出现问题,无法打开此文档。如果此情况持续发生,请尝试在 Microsoft Word 中打开文档。
if(docvalue.indexOf("很抱歉,出现问题,无法打开此文档。如果此情况持续发生,请尝试在 Microsoft Word 中打开文档。")>-1){
$(".btndiv").show();
}
}
//运行时错误
var runtimeError = $($("#docViewer").get(0).contentWindow.document.body).find("title").html();
if(runtimeError != undefined && runtimeError == "运行时错误"){
$(".btndiv").show();
}
});
}
else
{
iframe.onload = function() {
var docvalue = $($("#docViewer").get(0).contentWindow.document.body).find("#WACDialogText").html();
if(docvalue != undefined){
if(docvalue.indexOf("很抱歉,遇到问题,无法打开此演示文稿。请重试。")>-1){
$(".btndiv").show();
}
//很抱歉,出现问题,无法打开此文档。如果此情况持续发生,请尝试在 Microsoft Word 中打开文档。
if(docvalue.indexOf("很抱歉,出现问题,无法打开此文档。如果此情况持续发生,请尝试在 Microsoft Word 中打开文档。")>-1){
$(".btndiv").show();
}
//很抱歉,出现问题,无法打开此PDF。如果此情况持续发生,请尝试在 Microsoft Word 中打开PDF。
if(docvalue.indexOf("很抱歉,出现问题,无法打开此PDF。如果此情况持续发生,请尝试在 Microsoft Word 中打开PDF。")>-1){
$(".btndiv").show();
}
//很抱歉,Word Web App 打开此文档时遇到问题。 要查看此文档,请在 Microsoft Word 中打开它。
if(docvalue.indexOf("很抱歉,Word Web App 打开此文档时遇到问题。 要查看此文档,请在 Microsoft Word 中打开它")>-1){
$(".btndiv").show();
}
}
//运行时错误
var runtimeError = $($("#docViewer").get(0).contentWindow.document.body).find("title").html();
if(runtimeError != undefined && runtimeError == "运行时错误"){
$(".btndiv").show();
}
}
}
});
function changePreview(){
$(".btndiv").show();
var url_ms = $("input[name='wms']").val();//微软预览方式
var way_365 = $("input[name='w365']").val();//微软预览方式
var myUrl = parseURL(way_365);
var _365Url = myUrl.protocol+"://"+myUrl.host;
if(myUrl.port){
_365Url += ":"+myUrl.port;
}
// msUrl_ = "http://docviewer.mulinquan.com";
var codepreviewurl = window.btoa("prewurl="+way_365+"&wms="+url_ms+"&errorMsg=error");
var locationurl = _365Url+"/preview.html?"+codepreviewurl;
window.location.href = locationurl;
}
function showPreviewMsg(){
}
//自适应高度
function changeFrameHeight(){
var ifm= document.getElementById("docViewer");
ifm.height=document.body.clientHeight;
}
window.onresize=function(){
changeFrameHeight();
}
//根据内容改变iframe高度
function iframeAutoHeight(){
var iframe=document.getElementById("docViewer");
//浏览器类型判断
if(navigator.userAgent.indexOf("MSIE")>0||navigator.userAgent.indexOf("rv:11")>0||navigator.userAgent.indexOf("Firefox")>0){
iframe.height=iframe.contentWindow.document.body.scrollHeight;
}else{
iframe.height=iframe.contentWindow.document.documentElement.scrollHeight;
}
}
//url字符串解析
function parseURL(url) {
var a = document.createElement('a');
a.href = url;
return {
source: url,
protocol: a.protocol.replace(':',''),
host: a.hostname,
port: a.port,
query: a.search,
params: (function(){
var ret = {},
seg = a.search.replace(/^\?/,'').split('&'),
len = seg.length, i = 0, s;
for (i;i<len;i++) {
if (!seg[i]) { continue; }
s = seg[i].split('=');
ret[s[0]] = s[1];
}
return ret;
})(),
file: (a.pathname.match(/\/([^\/?#]+)$/i) || [,''])[1],
hash: a.hash.replace('#',''),
path: a.pathname.replace(/^([^\/])/,'/$1'),
relative: (a.href.match(/tps?:\/\/[^\/]+(.+)/) || [,''])[1],
segments: a.pathname.replace(/^\//,'').split('/')
};
}
var t1 = window.setInterval(showTip,1000);
function showTip(){
var docvalue = $($("#docViewer").get(0).contentWindow.document.body).find("#WACDialogText").html();
if(docvalue != undefined){
if(docvalue.indexOf("很抱歉,遇到问题,无法打开此演示文稿。请重试。")>-1){
if(errorMsg != "error"){
changePreview();
}else{
showPreMsg()
}
}
//很抱歉,出现问题,无法打开此文档。如果此情况持续发生,请尝试在 Microsoft Word 中打开文档。
if(docvalue.indexOf("很抱歉,出现问题,无法打开此文档。如果此情况持续发生,请尝试在 Microsoft Word 中打开文档。")>-1){
if(errorMsg != "error"){
changePreview();
}else{
showPreMsg()
}
}
//很抱歉,出现问题,无法打开此PDF。如果此情况持续发生,请尝试在 Microsoft Word 中打开PDF。
if(docvalue.indexOf("很抱歉,出现问题,无法打开此PDF。如果此情况持续发生,请尝试在 Microsoft Word 中打开PDF。")>-1){
if(errorMsg != "error"){
changePreview();
}else{
showPreMsg()
}
}
//很抱歉,Word Web App 打开此文档时遇到问题。 要查看此文档,请在 Microsoft Word 中打开它。
if(docvalue.indexOf("很抱歉,Word Web App 打开此文档时遇到问题。 要查看此文档,请在 Microsoft Word 中打开它")>-1){
if(errorMsg != "error"){
changePreview();
}else{
showPreMsg()
}
}
//很抱歉,Word Web App 打开此文档时遇到问题。 要查看此文档,请在 Microsoft Word 中打开它。
if(docvalue.indexOf("很抱歉")>-1 || docvalue.indexOf("遇到问题")>-1 || docvalue.indexOf("无法打开")>-1 || docvalue.indexOf("出现问题")>-1){
if(errorMsg != "error"){
changePreview();
}else{
showPreMsg()
}
}
}
//无法打开此工作簿
var errorTxt = $($("#docViewer").get(0).contentWindow.document.body).find("#errorText").html();
if(errorTxt != undefined){
if(errorTxt.indexOf("无法打开此工作簿")>-1 || errorTxt.indexOf("很抱歉")>-1 || errorTxt.indexOf("遇到问题")>-1 || errorTxt.indexOf("无法打开")>-1 || errorTxt.indexOf("出现问题")>-1 ||errorTxt.indexOf("问题")>-1 ){
if(errorMsg != "error"){
changePreview();
}else{
showPreMsg()
}
}
}
var isShow = $(".btndiv").css("display");
if(isShow == "block"){
window.clearInterval(t1);
}
}
setTimeout(showTip_,5000);
function showTip_(){
var isShow = $($("#docViewer").get(0).contentWindow.document.body).find("#load_back").css("display");
if(isShow == "block"){
changePreview();
}
}
function showPreMsg(){
$(".btndiv").show();
$(".tip_font").html("当前文档为空或者错误,不可在线预览,可尝试下载后打开");
$("#btnclose").show();
}
</script>
<style type="text/css">
body {overflow: hidden;}
.btndiv {
position:absolute;
top: 50%;
left: 50%;
margin-left: -189px; margin-top: -62px; }
.stat-tip{padding:10px 15px;}
.alert-info{color:#31708f;background-color:#d9edf7;border-color:#bce8f1;}
.alert{padding: 15px; margin-bottom: 20px; border: 1px solid transparent;border-radius: 4px;}
.mv-20 {
margin-top: 20px!important;
margin-bottom: 20px!important;
height:auto !important;
min-height:130px;
width:400px;
}
.button {
outline: none;
cursor: pointer;
text-align: center;
text-decoration: none;
font: 16px/100% 'Microsoft yahei',Arial, Helvetica, sans-serif;
-webkit-border-radius: .5em;
-moz-border-radius: .5em;
border-radius: .3em;
-webkit-box-shadow: 0 1px 2px rgba(0,0,0,.2);
-moz-box-shadow: 0 1px 2px rgba(0,0,0,.2);
box-shadow: 0 1px 2px rgba(0,0,0,.2);
display: inline-block;
}
.button:hover {
text-decoration: none;
}
.button:active {
position: relative;
top: 1px;
}
/* white */
.white {
color: #5d5b5b;
font-size: 14px;
padding: 8px 20px;
text-align: center;
width: 30px;
height: 15px;
border: solid 1px #cacaca;
background: #fff;
background: -webkit-gradient(linear, left top, left bottom, from(#fff), to(#ededed));
}
.white:hover {
background: #ededed;
background: -webkit-gradient(linear, left top, left bottom, from(#fff), to(#dcdcdc));
background: -moz-linear-gradient(top, #fff, #dcdcdc);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffff', endColorstr='#dcdcdc');
}
.white:active {
color: #999;
background: -webkit-gradient(linear, left top, left bottom, from(#ededed), to(#fff));
background: -moz-linear-gradient(top, #ededed, #fff);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ededed', endColorstr='#ffffff');
}
.viewbtn{
position: absolute;
right: 5%;
top: 58%;
margin-top: 8px;
}
.tip_font{
position: absolute;
font-size: 16px;
margin-left: 50px;
}
h3{
margin: 10px 5px;
}
.changeBtn{
position: fixed;
margin-left: 92%;
margin-top: 47%;
}
</style>
</HEAD>
<BODY style="margin:0px;">
<input type="hidden" name = "w365"/>
<input type="hidden" name = "wms"/>
<div class="btndiv alert stat-tip alert-info mv-20" style="display: none; margin-top: -80px !important; margin-left: -207px;">
<h3><font color="red">提示:</font></h3>
<div class="tip_font">
文档预览正在生成中,请稍等...
</div>
<a href="#" class="button white" onclick="window.close();" style="display: none" id="btnclose">关闭</a>
</div>
<a class="changeBtn button white " onclick="changePreview();" title = '若预览失败,可切换其他方式预览'>切换</a>
<iframe id="docViewer" width="100%" height="100%" allowtransparency = "yes" marginwidth="0" marginheight="0" frameborder="0" src="#" style="border: 0px solid;" scrolling="yes">
</iframe>
</BODY>
</HTML>