导航:首页 > 编程语言 > 引入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代码相关的资料

热点内容
暴风转码如何添加文件夹 浏览:515
延安整合网络营销有哪些 浏览:74
查找word打开过的文件在哪里 浏览:137
b树java代码 浏览:683
电脑文件存储 浏览:657
兰州中考征集志愿在哪个网站 浏览:215
cs文件上传下载 浏览:244
拷贝文件到根目录下重命名linux 浏览:603
api函数的头文件 浏览:249
华为怎么绑定迷你编程 浏览:215
机构怎么申请少儿编程考级 浏览:495
昆山数控编程哪里好学 浏览:459
jspcfor跳出 浏览:65
word怎么插入罗马数字i 浏览:315
哪个网站可以找到法人代表 浏览:106
苹果5s日版a1453支持什么网络 浏览:297
微信打开文件如何设置 浏览:218
漫画书app中非可视组件是什么 浏览:3
d盘文件隐藏怎么恢复 浏览:287
5s怎么设置联通4g网络 浏览:15

友情链接