张银的博客


Eat to live, but do not live to eat.

导航

view-source,JavaScript 查看网页源代码

Posted on 2009-03-31 22:32  张银  阅读(2674)  评论(0编辑  收藏  举报

第一种:view-source法

  view-source是一种协议,早期基本上每个浏览器都支持这个协议。但是不知道什么原因,从IE6 Beta2以后IE就不再支持此协议了。这个方法现在只能用在FireFox浏览器上使用了!
  使用方法一举例:在浏览器地址栏中输入
  view-source:http://aidd2008.cnblogs.com/
  回车即可看到网页的源代码了。
  使用方法二:
  <input id="bn1" type="button" onclick="window.location = 'view-source:' + window.location.href" value="查看源文件" />



第二种:JavaScript法

  这种方法似乎也不是通用的,在IE6和Opere浏览器上试验成功,但是在FireFox浏览器上就没成功!
  使用方法一:在浏览器地址栏中输入
  javascript:s=document.documentElement.outerHTML;document.write("");document.body.innerText=s; (错误的,不知需要如何改动)
  回车即可看到网页的源代码了。
  使用方法二:
  <input id="bn" type="button" onclick="javascript:document.body.innerText=document.documentElement.outerHTML;" value="查看源文件" />