文件包含、调用是个常见问题,稍作整理,发现居然有九点之多。
1.<script>标签
<script src="include.js"></script>
需要注意的是include.js里不能再包含<script>和</script>,扩展名随意,所有内容必须经由document.write()输出
把内容用下面的脚本转换成这种形式
<style>
body{margin:0;overflow:hidden}
textarea{width:100%;height:33%;font-size:9pt;font-family:Courier New;color:#666666}</style>
<textarea id="oSource" onpropertychange="change()"></textarea><br />
<textarea id="oResult" onpropertychange="rechange()" ondblclick='this.select();oResult.createTextRange().execCommand("Copy")' title="双击复制" ></textarea>
<textarea id="Re" ondblclick='this.select();this.createTextRange().execCommand("Copy")' title="双击复制"></textarea>
<script>
function change(){
oResult.value="document.writeln(\""+oSource.value.replace(/\\/g,"\\\\").replace(/\//g,"\\/").replace(/\'/g,"\\\'").replace(/\"/g,"\\\"").split('\r\n').join("\");\ndocument.writeln(\"")+"\")"
}
function rechange(){
Re.value=oResult.value.replace(/document.writeln\("/g,"").replace(/"\);/g,"").replace(/\\\"/g,"\"").replace(/\\\'/g,"\'").replace(/\\\//g,"\/").replace(/\\\\/g,"\\")
}
</script>
2.iframe
这个不用多解释了,有疑问的话请参考
<a href="http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/objects/iframe.asp">MSDN</a>,还有以前做过的一个Object插件:<a href="http://www.x-lover.com/down.asp?d=8&e=2&name=iframe">iframe</a>
<iframe src="index.asp"></iframe>
3.Object(Scriptlets组件)
<br>有滚动条<br>
<object data="index.asp" type="text/html" width=400 height=300></object>
<br>无滚动条<br>
<object style="border: 0px" type="text/x-scriptlet" data="index.asp" width=400 Height=300></object>
4.SSI
ASP:
<!--#include file="index.asp"-->
<!--#include virtual="/index.asp"-->
PHP:
include("index.php")
5.Server.Transfer,Server.Execute(ASP)
server.execute ("index.asp")
server.transfer ("index.asp")
6.FSO
<%
TF=Server.Mappath("index.asp")
set fs=server.createobject("scripting.filesystemobject")
set ts=fs.opentextfile(TF)
Do While(ts.atendofstream<>true)
response.write(ts.readline)
Loop
ts.close
%>
7.download Behavior
<SCRIPT>
function oBehavior(url){
with(event.srcElement){
addBehavior('#default#download')
startDownload(url,oDownload)
}}
function oDownload(oSource){
viewfield.innerHTML=oSource
}
</SCRIPT>
<button onClick=oBehavior("index.asp")>index.asp</button>
<span id="viewfield">内容暂缺</span>
8.XMLHTTP
<script>
function getit(url){
with(new ActiveXObject("Microsoft.XMLHTTP")){
open("get",url,false,"","")
send()
viewfield.innerHTML=ResponseText
}
}
</script>
<button onClick=getit("index.asp")>index.asp</button>
<span id="viewfield">内容暂缺</span>
XMLHTTP方式需要注意,目标文件最好保存编码为Unicode或者UTF-8,否则会出现乱码。当然,还有解决的方法,用下面的函数把返回的ResponseText处理一下,只是这样效率比较低,文件较大时不推荐使用。
<script language=vbscript>
function bytes2bstr(vin)
strreturn = ""
for i = 1 to lenb(vin)
thischarcode = ascb(midb(vin,i,1))
if thischarcode < &h80 then
strreturn = strreturn & chr(thischarcode)
else
nextcharcode = ascb(midb(vin,i+1,1))
strreturn = strreturn & chr(clng(thischarcode) * &h100 + cint(nextcharcode))
i = i + 1
end if
next
bytes2bstr = strreturn
end function
</script>
另外,XMLHTTP这种方法也可以在后台程序中用,不过要作相应修改
9.HTC
包含页代码:
<span style="behavior:url(index.htc)"></span>
被包含页index.htc:
<public:attach event="oncontentready" onevent="loadit()" />
<script>
function loadit(){
insertAdjacentHTML("afterBegin", include.innerHTML)
}
</script>
<xmp id="include">
被包含内容
<a href=http://www.flash8.net>flash8</a>
</xmp>
1.<script>标签
<script src="include.js"></script>
需要注意的是include.js里不能再包含<script>和</script>,扩展名随意,所有内容必须经由document.write()输出
把内容用下面的脚本转换成这种形式
<style>
body{margin:0;overflow:hidden}
textarea{width:100%;height:33%;font-size:9pt;font-family:Courier New;color:#666666}</style>
<textarea id="oSource" onpropertychange="change()"></textarea><br />
<textarea id="oResult" onpropertychange="rechange()" ondblclick='this.select();oResult.createTextRange().execCommand("Copy")' title="双击复制" ></textarea>
<textarea id="Re" ondblclick='this.select();this.createTextRange().execCommand("Copy")' title="双击复制"></textarea>
<script>
function change(){
oResult.value="document.writeln(\""+oSource.value.replace(/\\/g,"\\\\").replace(/\//g,"\\/").replace(/\'/g,"\\\'").replace(/\"/g,"\\\"").split('\r\n').join("\");\ndocument.writeln(\"")+"\")"
}
function rechange(){
Re.value=oResult.value.replace(/document.writeln\("/g,"").replace(/"\);/g,"").replace(/\\\"/g,"\"").replace(/\\\'/g,"\'").replace(/\\\//g,"\/").replace(/\\\\/g,"\\")
}
</script>
2.iframe
这个不用多解释了,有疑问的话请参考
<a href="http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/objects/iframe.asp">MSDN</a>,还有以前做过的一个Object插件:<a href="http://www.x-lover.com/down.asp?d=8&e=2&name=iframe">iframe</a>
<iframe src="index.asp"></iframe>
3.Object(Scriptlets组件)
<br>有滚动条<br>
<object data="index.asp" type="text/html" width=400 height=300></object>
<br>无滚动条<br>
<object style="border: 0px" type="text/x-scriptlet" data="index.asp" width=400 Height=300></object>
4.SSI
ASP:
<!--#include file="index.asp"-->
<!--#include virtual="/index.asp"-->
PHP:
include("index.php")
5.Server.Transfer,Server.Execute(ASP)
server.execute ("index.asp")
server.transfer ("index.asp")
6.FSO
<%
TF=Server.Mappath("index.asp")
set fs=server.createobject("scripting.filesystemobject")
set ts=fs.opentextfile(TF)
Do While(ts.atendofstream<>true)
response.write(ts.readline)
Loop
ts.close
%>
7.download Behavior
<SCRIPT>
function oBehavior(url){
with(event.srcElement){
addBehavior('#default#download')
startDownload(url,oDownload)
}}
function oDownload(oSource){
viewfield.innerHTML=oSource
}
</SCRIPT>
<button onClick=oBehavior("index.asp")>index.asp</button>
<span id="viewfield">内容暂缺</span>
8.XMLHTTP
<script>
function getit(url){
with(new ActiveXObject("Microsoft.XMLHTTP")){
open("get",url,false,"","")
send()
viewfield.innerHTML=ResponseText
}
}
</script>
<button onClick=getit("index.asp")>index.asp</button>
<span id="viewfield">内容暂缺</span>
XMLHTTP方式需要注意,目标文件最好保存编码为Unicode或者UTF-8,否则会出现乱码。当然,还有解决的方法,用下面的函数把返回的ResponseText处理一下,只是这样效率比较低,文件较大时不推荐使用。
<script language=vbscript>
function bytes2bstr(vin)
strreturn = ""
for i = 1 to lenb(vin)
thischarcode = ascb(midb(vin,i,1))
if thischarcode < &h80 then
strreturn = strreturn & chr(thischarcode)
else
nextcharcode = ascb(midb(vin,i+1,1))
strreturn = strreturn & chr(clng(thischarcode) * &h100 + cint(nextcharcode))
i = i + 1
end if
next
bytes2bstr = strreturn
end function
</script>
另外,XMLHTTP这种方法也可以在后台程序中用,不过要作相应修改
9.HTC
包含页代码:
<span style="behavior:url(index.htc)"></span>
被包含页index.htc:
<public:attach event="oncontentready" onevent="loadit()" />
<script>
function loadit(){
insertAdjacentHTML("afterBegin", include.innerHTML)
}
</script>
<xmp id="include">
被包含内容
<a href=http://www.flash8.net>flash8</a>
</xmp>
















