手机
当前位置:查字典教程网 >网页设计 >HTML5教程 >在html页面中包含静态或动态页面方法
在html页面中包含静态或动态页面方法
摘要:1.可以用download行为下载后再用innerHTML特性显示出来。具体步骤:functionwindow.onload(){demo....

1.可以用 download 行为下载后再用 innerHTML 特性显示出来。 
具体步骤:

<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> 
     
被调用页demo.htm的代码。 
     
<span style="color:red;font:bold 12px Tahoma"> 
测试 演示 TEST test DEMO demo</span>

注意:在本例中id为demo的对象必须设置它的默认行为为download。
 


2.script。需要注意的是include.js里不能再包含<script>和</script>,扩展名随意,所有内容必须经由 write()、wirteln()、innerHTML、innerText、outerHTML或outerText 输出显示。代码示例:

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

 <script language="JavaScript" src="http://www.newsccn.com/count.php?contentid={$contentid}"></script>

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

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

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

5.SSI(服务器端包含)。代码示例:

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

 

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

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

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

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 函数获取此回调函数的指针。

【在html页面中包含静态或动态页面方法】相关文章:

HTML5布局标签属性和方法

html5中JavaScript removeChild 删除所有节点

html5 svg 中元素点击事件添加方法

html5 touch事件实现触屏页面上下滑动(二)

HTML页面中添加Canvas标签示例

HTML4和HTML5之间除了相似以外的10个主要不同

html5 touch事件实现页面上下滑动效果【附代码】

HTML5 Web Database 数据库的SQL语句的使用方法

HTML5 Web Workers之网站也能多线程的实现

HTML5中meta属性的使用方法

精品推荐
分类导航