getImageData in Firefox 3 causing NS_ERROR_DOM_SECURITY_ERR

删除回忆录丶 提交于 2019-12-06 11:17:43

You could try installing a local webserver such as Apache (on unix) or IIS (on Windows). That will ultimately give you the best local test bench for web-related stuff, because as you have found out browsers treat files from the filesystem quite differently than content served from a webserver.

You can tell the browser to bug off. The solution is better or worse depending on your circumstances. I wrap it in a try so no security dialog will be presented if it's not an issue.

  var data;
  try {
    try {
      data = context.getImageData(sx, sy, sw, sh).data;
    } catch (e) {
      netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
      data = context.getImageData(sx, sy, sw, sh).data;
    }
  } catch (e) {
    throw new Error("unable to access image data: " + e);
  }

In Firefox, type "about:config" into your address bar. Then use the search field to search for "security.fileuri.strict_origin_policy". Double click this to set it to "false".

nodehi

I had the same problem while using getImageData in FireFox 11.0 ... All my files and codes were on my server and there was nothing on my local computer.

I thought maybe this helps someone who has the same problem as me.

It looks like that Firefox treats

http://mySite.com

as a different domain from

http://www.mySite.com

So I used .htaccess to add www. when users don't type it in

RewriteEngine On
RewriteCond %{HTTP_HOST} ^mySite\.com$ [NC]
RewriteRule ^(.*)$ http://www.mySite.com/$1 [L,R=301]

Now it works fine and doesn't show NS_ERROR_DOM_SECURITY_ERR anymore.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!