导航:首页 > 编程语言 > 引入html代码

引入html代码

发布时间:2023-08-20 15:16:52

㈠ 在html文件引入其它html文件的几种方法

简介:在论坛中常常有网友问到,可以在一个html的文件当中读取另一个html文件的内容吗?答案是确定的,而且方法不只一种,在以前我只会使用iframe来引用,后来发现了另外的几种方法,那今天就总结这几种方法让大家参考一下,本人觉得第三种方式较好! 1.IFrame引入,看看下面的代码 <IFRAME NAME="content_frame" width=100% height=30 marginwidth=0 marginheight=0 SRC="import.htm" </IFRAME 你会看到一个外部引入的文件,但会发现有一个类似外框的东西将其包围,可使用:<iframe name="content_frame" marginwidth=0 marginheight=0 width=100% height=30 src="import.htm" frameborder=0</iframe 但你会发现还会有点问题,就是背景色不同,你只要在引入的文件import.htm中使用相同的背景色也可以,但如果你使用的是IE5.5的话,可以看看这篇关于透明色的文章 如果想引入的文件过长时不出现滚动条的话在import.htm中的body中加入scroll=no 2.<object方式 <object style="border:0px" type="text/x-scriptlet" data="import.htm" width=100% height=30</object 3.Behavior的download方式 <span id=showImport</span <IE:Download ID="oDownload" STYLE="behavior:url(#default#download)" /<scriptfunction onDownloadDone(downDate){

㈡ 请问html页面怎么引入公共的Html页面呢

<!--第一种:jquery获取dom内的id,直接加载想要引入的页面-->

<divid="page"></div>
<script>
$("#page").load("header.html");
</script>
<!--第二种:引入include.js文件,然后用include标签加载想要的页面
代码如下-->

<script>
(function(window,document,undefined){
varInclude39485748323=function(){}
Include39485748323.prototype={
//倒序循环
forEach:function(array,callback){
varsize=array.length;
for(vari=size-1;i>=0;i--){
callback.apply(array[i],[i]);
}
},
getFilePath:function(){
varcurWwwPath=window.document.location.href;
varpathName=window.document.location.pathname;
varlocalhostPaht=curWwwPath.substring(0,curWwwPath.indexOf(pathName));
varprojectName=pathName.substring(0,pathName.substr(1).lastIndexOf('/')+1);
returnlocalhostPaht+projectName;
},
//获取文件内容
getFileContent:function(url){
varie=navigator.userAgent.indexOf('MSIE')>0;
varo=ie?newActiveXObject('Microsoft.XMLHTTP'):newXMLHttpRequest();
o.open('get',url,false);
o.send(null);
returno.responseText;
},
parseNode:function(content){
varobjE=document.createElement("div");
objE.innerHTML=content;
returnobjE.childNodes;
},
executeScript:function(content){
varmac=/<script>([sS]*?)</script>/g;
varr="";
while(r=mac.exec(content)){
eval(r[1]);
}
},
getHtml:function(content){
varmac=/<script>([sS]*?)</script>/g;
content.replace(mac,"");
returncontent;
},
getPrevCount:function(src){
varmac=/..//g;
varcount=0;
while(mac.exec(src)){
count++;
}
returncount;
},
getRequestUrl:function(filePath,src){
if(/http:///g.test(src)){returnsrc;}
varprevCount=this.getPrevCount(src);
while(prevCount--){
filePath=filePath.substring(0,filePath.substr(1).lastIndexOf('/')+1);
}
returnfilePath+"/"+src.replace(/..//g,"");
},
replaceIncludeElements:function(){
var$this=this;
varfilePath=$this.getFilePath();
varincludeTals=document.getElementsByTagName("include");
this.forEach(includeTals,function(){
//拿到路径
varsrc=this.getAttribute("src");
//拿到文件内容
varcontent=$this.getFileContent($this.getRequestUrl(filePath,src));
//将文本转换成节点
varparent=this.parentNode;
varincludeNodes=$this.parseNode($this.getHtml(content));
varsize=includeNodes.length;
for(vari=0;i<size;i++){
parent.insertBefore(includeNodes[0],this);
}
//执行文本中的额javascript
$this.executeScript(content);
parent.removeChild(this);
//替换元素this.parentNode.replaceChild(includeNodes[1],this);
})
}
}
window.onload=function(){
newInclude39485748323().replaceIncludeElements();
}
})(window,document)
</script>
<!--下面引入文件-->
<includesrc="header.html"></include>

<!--第三种:用inframe框架加载页面,兼容性不好-->

<iframesrc="xxx.html"></iframe>

㈢ html页面怎么引入html代码

直接在html文件写入html代码即可。 最简单的方法就是新建一个记事本,然后在记事本里面写入自己的html代码,写完之后ctrl+shift+s另存为html文件,双击打开这个文件就可以自动在浏览器运行了。 不过初学者的话建议还是使用一些像DW这样的编辑器软件来辅助自己编写html代码。 --河南新华网络运营协会为您解答!

阅读全文

与引入html代码相关的资料

热点内容
ps3文件分割视频 浏览:280
微信图片一键转发软件 浏览:331
如何判断s200plc编程电缆 浏览:691
太原编程培训班哪个好 浏览:171
树叶吹奏教程 浏览:6
社交app带来了哪些社会问题 浏览:394
如何安装爱宝8800数据采集器 浏览:712
文件保存了怎么找不到了 浏览:476
彩票网站怎么辨真假 浏览:840
pr找不到该文件 浏览:963
java移除panel 浏览:354
jsp填充jsp 浏览:166
海关外贸大数据在哪里查 浏览:381
思特奇java笔试题 浏览:121
葫芦侠在手机中的文件名 浏览:813
plc编程应该怎么收钱 浏览:584
c语言中源文件由什么组成 浏览:890
linuxhttpdphp配置文件 浏览:607
拆单数据要怎么保存 浏览:17
mac电脑怎样压缩文件到100m 浏览:645

友情链接