如果本地的javascript要访问远程的内容,在firefox里因为安全性的考虑,缺省的话是不能访问的。在tools ->error console里会出来一下类似:
security error, file at ... may not load data from ...的提示。
参考http://www.mozilla.org/projects/security/components/jssec.html里讲的,在我们的javascript里增加一句:
netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
netscape.security.PrivilegeManager.enablePrivilege("UniversalFileRead");
这时执行的时候firefox是弹出一个对话框,这里点确定,就可以成功调用了。
附我的一段code:
[code]
function ajaxdecode() {
netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
netscape.security.PrivilegeManager.enablePrivilege("UniversalFileRead");
xmlhttp.open("GET", 'http://xx.xx.xxx.xx/code.php?type=' + $('type').value + "&text=" + $('text').value , true);
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4) {
document.getElementById('result').innerHTML = xmlhttp.responseText;
}
}
xmlhttp.send(null );
return false;
}
[/code]
firefox本地javascript 调用远程的办法
最新推荐文章于 2020-03-11 14:04:01 发布
2630

被折叠的 条评论
为什么被折叠?



