如果本地的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:
function ajaxdecode() {
netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
netscape.security.PrivilegeManager.enablePrivilege("UniversalFileRead");
xmlhttp.open("GET", 'http://xx.xx.xx.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;
}
本文介绍如何解决Firefox浏览器中JavaScript跨域访问的问题,并提供了一个具体的示例代码,通过启用特定权限来实现远程内容的加载。
1101

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



