=波波日志 > JavaScript/Ajax > JavaScript获取当前页面的全部html代码=
JavaScript获取当前页面的全部html代码
使用JavaScript获取当前页面的所有html代码,包括文档申明,html根节点。
第一种方法,使用ajax来加载页面,如下
第二种方法,使用innerHTML,不过在IE核心的浏览器会把tag标签变为大写的,如果不在意大小写,可以使用如下代码。
第一种方法,使用ajax来加载页面,如下
+展开
-HTML
<script>
var q=XMLHttpRequest?new XMLHttpRequest():new ActiveXObject("Microsoft.XMLHTTP");
q.open("GET",location.href,false);
q.send();
document.write(q.responseText.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">"))
</script>
var q=XMLHttpRequest?new XMLHttpRequest():new ActiveXObject("Microsoft.XMLHTTP");
q.open("GET",location.href,false);
q.send();
document.write(q.responseText.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">"))
</script>
第二种方法,使用innerHTML,不过在IE核心的浏览器会把tag标签变为大写的,如果不在意大小写,可以使用如下代码。
+展开
-JavaScript
function encode(v){return v.replace(/</g,'<');}
window.onload=function(){
var pre=document.createElement('pre');
pre.innerHTML=typeof(HTMLElement) != "undefined"?
encode(document.createElement("DIV").appendChild(document.documentElement.cloneNode(true)).parentNode.innerHTML):encode(document.documentElement.outerHTML);
document.body.appendChild(pre);
}
window.onload=function(){
var pre=document.createElement('pre');
pre.innerHTML=typeof(HTMLElement) != "undefined"?
encode(document.createElement("DIV").appendChild(document.documentElement.cloneNode(true)).parentNode.innerHTML):encode(document.documentElement.outerHTML);
document.body.appendChild(pre);
}
类别:JavaScript/Ajax 作者:波波 日期:2010-05-27 【评论:0】
暂时没有评论!
发表留言
百度赞助
同类热门博文
- ·AJAX跨域问题解决办..
- ·ajax问题总结
- ·jQuery dataType指定..
- ·ajax+asp.net+mssql..
- ·ajax无刷新上传文件..
- ·ajax对象abort方法
- ·JavaScript代码,变..
- ·fckeditor编辑器在F..
博格Tag
- flash/flex/fcs/AIR(752)
- Asp.Net/C#/WCF(598)
- 操作系统及应用软件(376)
- JavaScript/Ajax(330)
- SQL及数据库(134)
- 黑客技术(115)
- Asp/VBScript(111)
- HTML/WML/CSS兼容/XML(102)
- PHP/apache/Perl(96)
- 网站排名及优化(96)
- 其他(75)
- showbo日志(66)
- lucene.net/分词技术(33)
- 计算机网络(26)
- 机械重工(26)
- C#设计模式(25)
- Google Maps开发(17)
- 日语学习(15)
- Canvas/VML/SVG(13)
- linux(11)
- 游戏开发(8)
- 正则表达式(5)
- Jsp/Java(4)
最新博文
- ·javascript实现html..
- ·Javascript风格要素..
- ·Javascript风格要素
- ·动态加载JavaScript
- ·JavaScript陷阱
- ·ajax技巧
- ·IE对CSS样式表的限制..
- ·什么是Javascript匿..
随机博文
