不用 iframe 和 SSI 能否实现包含页(转贴)

不用 iframe 和 SSI 能否实现包含页(转贴)

原地址:http://www2.flash8.net/teach/4014.htm

主要是asp下面的实现。很多都可以在其他地方应用。

不用 iframe 和 SSI 能否实现包含页

作者:闪吧   类型:原创   来源:闪吧
style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; WIDTH: 400px; PADDING-TOP: 0px; HEIGHT: 25px" src="teachInfo.aspx?id=4014" frameborder="0" scrolling="no">
   不用 iframe 和 SSI 能否实现包含页
解决思路
可以用 download 行为下载后再用 innerHTML 特性显示出来。
具体步骤
1.调用页代码。

<span id="demo" src="demo.htm" _fcksavedurl=""demo.htm"" _fcksavedurl=""demo.htm""
 style="behavior:url(#default#download)"></span> 
<SCRIPT>
 function window.onload(){
   demo.startDownload(demo.src,fnDownload)
 }
 function fnDownload(oSource){
   demo.innerHTML=oSource
 }
 </SCRIPT>
    
2.被调用页demo.htm的代码。
    
<span style="color:red;font:bold 12px Tahoma">
测试 演示 TEST test DEMO demo</span>

注意:在本例中id为demo的对象必须设置它的默认行为为download。
技巧:笔者总结的包含调用文件的9种方法:
1.script。需要注意的是include.js里不能再包含<script>和</script>,扩展名随意,所有内容必须经由 write()、wirteln()、innerHTML、innerText、outerHTML或outerText 输出显示。代码示例:

<script src="include.js"></script>

2.iframe。这个不用多解释了,有疑问的话请第一部分第六章。代码示例:

<iframe src="index.asp"></iframe>

3.Object(Scriptlets组件)。代码示例:

 有滚动条<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(服务器端包含)。代码示例:

<!--#include file="index.asp"-->
<!--#include virtual="/index.asp"-->

5.Server.Transfer,Server.Execute(ASP对象的方法)。代码示例:

server.execute ("index.asp")
server.transfer ("index.asp")

6.FSO(FileSystemObject,文件读写组件)代码示例:

<%
 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 行为。代码示例:

<span id="demo" src="demo.htm"
 style="behavior:url(#default#download)"></span> 
<SCRIPT>
 function window.onload(){
   demo.startDownload(demo.src,fnDownload)
 }
 function fnDownload(oSource){
   demo.innerHTML=oSource
 }
 </SCRIPT>

8.XMLHTTP组件。代码示例:

<script for="window" event="onload">
  with(new ActiveXObject("Microsoft.XMLHTTP")){
  open("get",demo.src,false,"","")
  send()
  demo.innerHTML=ResponseText
  }
</script>
 <span id="demo" src="demo.htm"></span>

需要注意,目标文件最好以Unicode或UTF-8编码保存,否则目标文件中的双字节文字会变成乱码。当然,可以用下面的函数把返回的ResponseText处理一下,但是这样效率比较低,文件较大时不推荐使用。XMLHTTP这种方法也可以在后台程序中使用。

<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>

9.HTC(HTML Component,将在下一章中介绍)。
(1)包含页代码。

<span style="behavior:url(index.htc)"></span>

(2)被包含页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>

特别提示
本例代码运行效果如图2.4.5所示,页面中所显示的文字为demo.htm页的。

图2.4.5 download行为应用效果
特别说明

download 行为的作用是下载文件并在下载完成后通知一个指定的回调函数,该行为只有一个startDownload方法:
startDownload 下载指定文件,该方法带两个参数,第一个参数为指定下载的文件地址,第二个参数为下载完成后要执行的代码的函数的指针。如果调用的函数是用 VBScript 脚本编写,需要使用 GetRef 函数获取此回调函数的指针。
   责任编辑:kissall    时间:2005年8月29日
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值