Firefox 3 中的 getImageData 导致 NS_ERROR_DOM_SECURITY_ERR

发布于 2024-07-09 11:28:35 字数 210 浏览 12 评论 0原文

我正在尝试开发一个在 Firefox 3 的 javascript 中使用 getImageData 的应用程序,但在 getImageData 调用中收到“NS_ERROR_DOM_SECURITY_ERR”。 javascript 和图像当前均由硬盘驱动器提供服务,这显然是一种安全违规? 当它上线时,它们都将由同一个域提供服务,所以这不会成为问题,但同时我该如何开发呢?

I'm trying to develop an application that will use getImageData in javascript in Firefox 3, but I am getting a "NS_ERROR_DOM_SECURITY_ERR" on the getImageData call. The javascript and the image are both currently being served from by hard drive, which is apparently a security violation? When this is live they will both be served from the same domain, so it won't be a problem, but how can I develop in the meantime?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

软糖 2024-07-16 11:28:35

您可以告诉浏览器关闭。 该解决方案是好还是坏取决于您的具体情况。 我将其包装在尝试中,因此如果不是问题,则不会显示安全对话框。

  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);
  }

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);
  }
梦里的微风 2024-07-16 11:28:35

您可以尝试安装本地网络服务器,例如 Apache(在 unix 上)或 IIS(在 Windows 上)。 这最终将为您提供与网络相关的内容的最佳本地测试平台,因为正如您所发现的,浏览器处理文件系统中的文件与网络服务器提供的内容完全不同。

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.

踏雪无痕 2024-07-16 11:28:35

在 Firefox 中,在地址栏中输入“about:config”。 然后使用搜索字段搜索“security.fileuri.strict_origin_policy”。 双击此项将其设置为“false”。

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".

〆凄凉。 2024-07-16 11:28:35

我在 FireFox 11.0 中使用 getImageData 时遇到了同样的问题...
我的所有文件和代码都在我的服务器上,我的本地计算机上没有任何内容。

我想这也许可以帮助那些和我有同样问题的人。

看起来 Firefox 将

http://mySite.com

其视为不同的域,

http://www.mySite.com

所以当用户不输入时,我使用 .htaccess 添加 www.

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

现在它工作正常并且不不再显示NS_ERROR_DOM_SECURITY_ERR

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文