Firefox进行测试,代码如下:
<html>
<head>
<script type="text/javascript">
var req = new XMLHttpRequest();
req.onreadystatechange = function(){
if(req.readyState!=4)return;
if(req.status == 200){
html=req.responseText;
alert(html);
}
}
window.onload=function(){
netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
try{
req.open("GET","http://www.newsmth.net",true);
req.send(null);
}catch(e){alert(e);}
}
</script>
</head>
<body>正在获取..</body>
</html>
对有些站点会在open语句处捕捉到异常:
[Exception... "Component returned failure code: 0x805e000a [nsIXMLHttpRequest.open]" nsresult: "0x805e000a (<unknown>)" location: "JS frame :: file:///G:/workspace/html/proxy.html :: anonymous :: line 15" data: no]
如:
http://ipcn.org,
http://www.g.cn--
FROM 59.66.186.*