FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
includeHTML/includeHTML.js at master · shot131/includeHTML · GitHub
shot131
/
includeHTML
Public
forked from
xmoonlight/includeHTML
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
includeHTML
/
includeHTML.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
92 lines (80 loc) · 2.88 KB
Breadcrumbs
includeHTML
/
includeHTML.js
Copy path
File metadata and controls
92 lines (80 loc) · 2.88 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
/*
License: CC BY-SA 4.0
Addition requirements: keep and copy license file into every software copy, keep and copy all license headers in files and license file without any changes.
Copyright (C) xmoonlight, 2016, All Rights Reserved
https://github.com/xmoonlight/includeHTML
*/
(
function
(
)
{
function
load
(
dst
,
url
,
callback
)
{
var
xmlhttp
;
if
(
window
.
XMLHttpRequest
)
xmlhttp
=
new
XMLHttpRequest
(
)
;
else
xmlhttp
=
new
ActiveXObject
(
"Microsoft.XMLHTTP"
)
;
xmlhttp
.
onreadystatechange
=
function
(
)
{
if
(
xmlhttp
.
readyState
==
XMLHttpRequest
.
DONE
)
{
if
(
xmlhttp
.
status
==
200
)
{
dst
.
innerHTML
=
xmlhttp
.
responseText
;
statusText
=
"success"
;
}
else
{
statusText
=
"error"
;
}
callback
(
xmlhttp
.
responseText
,
statusText
,
xmlhttp
)
;
}
}
try
{
xmlhttp
.
open
(
"GET"
,
url
,
true
)
;
xmlhttp
.
send
(
)
;
}
catch
(
e
)
{
callback
(
true
,
'error'
,
false
)
;
}
}
window
.
includeHTML
=
function
(
src
,
destination
,
callback
)
{
load
(
destination
,
src
,
function
(
response
,
status
,
xhr
)
{
if
(
status
==
"error"
)
{
var
iframe
=
document
.
createElement
(
'iframe'
)
;
iframe
.
onload
=
function
(
)
{
if
(
!
response
&&
document
.
location
.
protocol
.
indexOf
(
'http'
)
==
-
1
)
{
//всё, приехали...
if
(
navigator
.
userAgent
.
match
(
/
C
h
r
o
m
e
/
i
)
!==
-
1
)
//выводим подсказку.
msg
=
'For Chrome: add parameter in shortcut link:'
+
"\n"
+
'"path_chrome_dir\chrome.exe" --allow-file-access-from-files'
;
alert
(
navigator
.
userAgent
+
"\nResponse: "
+
response
+
"\nURL: "
+
src
+
"\n-------\n"
+
msg
)
;
}
destination
.
innerHTML
=
window
[
this
.
name
]
.
document
.
body
.
innerHTML
;
iframe
.
parentNode
.
removeChild
(
iframe
)
;
includeHTMLAuto
(
destination
)
;
if
(
callback
)
callback
(
)
;
}
iframe
.
style
.
display
=
'none'
;
iframe
.
name
=
'includer'
+
src
+
Math
.
random
(
)
;
iframe
.
src
=
src
;
document
.
body
.
appendChild
(
iframe
)
;
}
else
{
includeHTMLAuto
(
destination
)
;
if
(
callback
)
callback
(
)
;
}
}
)
;
}
function
includeHTMLAuto
(
node
)
{
var
includes
=
node
.
querySelectorAll
(
'include'
)
;
for
(
var
i
=
0
;
i
<
includes
.
length
;
i
++
)
{
includeHTML
(
includes
[
i
]
.
getAttribute
(
"src"
)
,
includes
[
i
]
)
;
}
}
var
oa
=
window
.
onload
;
window
.
onload
=
function
(
)
{
oa
&&
oa
(
)
;
includeHTMLAuto
(
document
.
body
)
;
}
}
)
(
)
;
/*
USAGE:
1.Tag: <div><include scr="menu.html"></include></div>
2.Async:
<script>
includeHTML('header.html', document.getElementById('header'));
includeHTML('menu.html', document.getElementById('mainMenu'));
</script>
3.Sync:
includeHTML('header.html', document.getElementById('header'), function(){
includeHTML('menu.html', document.getElementById('mainMenu'));
});
*/
Back
|
FazBrowse Home
|
New Git URL