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

热点内容
歌手实绩数据在哪里看 浏览:691
代码002 浏览:714
jdk如何编译java文件 浏览:900
修改iptables配置文件 浏览:427
word自动保存指定文件夹 浏览:18
电脑画质不清晰win10 浏览:912
diskgen使用教程 浏览:970
常州数控车编程培训哪里有 浏览:44
如何升级晴明等级 浏览:347
开头是什么文件 浏览:645
linux16进制看elf文件 浏览:663
纸档文件怎么能变成excel档 浏览:481
迅雷下载总出现jsp 浏览:150
创建网页用什么编程语言 浏览:526
考研哪个app好 浏览:30
计算机网络的概念是什么 浏览:625
网络硬盘存储制作 浏览:4
iphone怎么备份数据到电脑 浏览:41
微信小程序报表控件 浏览:722
ipad添加不了qq邮箱账号和密码 浏览:503

友情链接