显示当前网页的代码可以了,但是怎么在文本框显示其它固定网页的代码呢? -------------------------------------------------------------- <script language="vbscript"> Function bytes2BSTR(vIn) Dim strReturn,i,ThisCharCode,innerCode,Hight8,Low8,NextCharCode strReturn = "" For i = 1 To LenB(vIn) ThisCharCode = AscB(MidB(vIn,i,1)) If ThisCharCode < &H80 Then strReturn = strReturn & Chr(ThisCharCode) Else NextCharCode = AscB(MidB(vIn,i+1,1)) strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode)) i = i + 1 End If Next bytes2BSTR = strReturn End Function </script> <script language="javascript"> function viewcode(url) { var xmlhttp= new ActiveXObject("Msxml2.xmlhttp"); xmlhttp.open("GET",url,false); xmlhttp.send(); view.innerText=bytes2BSTR(xmlhttp.ResponseBody); } </script> <input type=button onclick="viewcode(newurl.value)" value="view"> <input type=text value="http://www.baidu.com/" id=newurl style="width:500"> <textarea style="width:100%;height:100%" id=view></textarea>
fastson()笔误
textareaName.value=document.body.innerHTML我来替他补充吧
就是将这句话作为一个对像的事件处理就行了
比如
<input type="button" onclick="textareaName.value=document.body.innerHTML;" value="显示源代码">不过这样显示的源代码和记事本中显示的还有点区别,主要是将一些动态生成的源代码也都显示出来了,直接一点说是应该比记事本中的那个更加完整
"http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=gb2312">
<TITLE>无标题文档</TITLE>
<SCRIPT language="javascript">
</SCRIPT>
</HEAD><BODY onLoad="document.all.txt.value=document.documentElement.innerHTML">
<TEXTAREA id="txt" cols="90" rows="20"></TEXTAREA>
<INPUT type="text" value="111">
</BODY>
</HTML>
中的documentElenment是什么对象?
但是不能显示其它网页的源文件(代码)??
textarea.value=document.documentElement.outerHTML;
能解决你的问题
或者利用xmlhttp
--------------------------------------------------------------
<script language="vbscript">
Function bytes2BSTR(vIn)
Dim strReturn,i,ThisCharCode,innerCode,Hight8,Low8,NextCharCode
strReturn = ""
For i = 1 To LenB(vIn)
ThisCharCode = AscB(MidB(vIn,i,1))
If ThisCharCode < &H80 Then
strReturn = strReturn & Chr(ThisCharCode)
Else
NextCharCode = AscB(MidB(vIn,i+1,1))
strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode))
i = i + 1
End If
Next
bytes2BSTR = strReturn
End Function
</script>
<script language="javascript">
function viewcode(url)
{
var xmlhttp= new ActiveXObject("Msxml2.xmlhttp");
xmlhttp.open("GET",url,false);
xmlhttp.send();
view.innerText=bytes2BSTR(xmlhttp.ResponseBody);
}
</script>
<input type=button onclick="viewcode(newurl.value)" value="view">
<input type=text value="http://www.baidu.com/" id=newurl style="width:500">
<textarea style="width:100%;height:100%" id=view></textarea>