Repository navigation
Expand file tree
/
Copy pathNavigator.js
More file actions
65 lines (59 loc) · 1.66 KB
/
Copy pathNavigator.js
File metadata and controls
65 lines (59 loc) · 1.66 KB
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
const Navigator = (function () {
let frame,
androidReg = /Android/gi,
isAndroid = androidReg.test(navigator.platform) || androidReg.test(navigator.userAgent);
frame = null;
function appendFrame(frame) {
frame && document.body.appendChild(frame);
}
function removeFrame(frame) {
frame && frame.parentNode.removeChild(frame);
}
function getFrame(src, name) {
let _frame = document.createElement('iframe');
_frame.setAttribute('style', 'display:none;width:0;height:0;position: absolute;top:0;left:0;border:0;');
_frame.setAttribute('height', '0px');
_frame.setAttribute('width', '0px');
_frame.setAttribute('frameborder', '0');
name && _frame.setAttribute('name', name);
if (src) {
_frame.setAttribute('src', src);
} else {
appendFrame(_frame);
}
return _frame;
}
function protocol(command, single, noframe) {
let _frame, timer;
if (noframe) {
window.location.href = command;
return;
}
if (single) {
if (isAndroid) {
_frame = getFrame();
_frame.setAttribute('src', command);
} else {
_frame = getFrame(command);
appendFrame(_frame);
}
timer = setTimeout(function () {
_frame && removeFrame(_frame);
}, 30000);
_frame.onload = _frame.onreadystatechange = function () {
timer && clearTimeout(timer);
_frame && removeFrame(_frame);
}
} else {
frame = frame || getFrame();
frame.setAttribute('src', command);
}
}
return {
protocol: protocol,
getFrame: getFrame,
appendFrame: appendFrame,
removeFrame: removeFrame
}
})();
export default Navigator;