当我尝试设置 cookie 时,未捕获错误:SECURITY_ERR:DOM 异常 18

发布于 2024-08-29 23:07:14 字数 327 浏览 4 评论 0原文

当我尝试使用 this jQuery 设置 cookie 时,我在 Chrome 的开发人员工具窗口中收到以下错误插件:

未捕获的错误:SECURITY_ERR:DOM 异常 18

此错误是什么意思以及如何修复它?当我使用 this jQuery 插件时,我遇到了同样的错误。

I get the following error in Chrome's developer tools window when I try to set a cookie using this jQuery plugin:

Uncaught Error: SECURITY_ERR: DOM Exception 18

What does this error mean and how can I fix it? I get the same error when I use this jQuery plugin.

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

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

发布评论

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

评论(9

单调的奢华 2024-09-05 23:07:14

您很可能通过 file:// URI 方案在本地文件上使用此功能,该方案无法设置 cookie。将其放在本地服务器上,以便您可以使用 http://localhost

You're most likely using this on a local file over the file:// URI scheme, which cannot have cookies set. Put it on a local server so you can use http://localhost.

何以畏孤独 2024-09-05 23:07:14

我在本地开发HTML5时也遇到了这个问题。
我遇到了图像和 getImageData 函数的问题。
最后,我发现可以使用 --allow-file-access-from-file 命令开关启动 chrome,从而摆脱这种保护安全性。
唯一的问题是,它使您的浏览器安全性降低,并且您不能让一个 chrome 实例打开该标志,而另一个 chrome 实例没有该标志。

I also had this issue while developping on HTML5 in local.
I had issues with images and getImageData function.
Finally, I discovered one can launch chrome with the --allow-file-access-from-file command switch, that get rid of this protection security.
The only thing is that it makes your browser less safe, and you can't have one chrome instance with the flag on and another without the flag.

皓月长歌 2024-09-05 23:07:14

您还可以通过将图像替换为其内联 Base64 表示形式来“修复”此问题:
<代码>

img.src= "data:image/gif;base64,R0lGODlhCwALAIAAAAAA3pn/ZiH5BAEAAAEALAAAAAALAAsAAAIUhA+hkcuO4lmNVindo7qyrIXiGBYAOw==";

Useful, when you do not intend to publish the page on the web, but instead use it on local machines only.

You can also "fix" this by replacing the image with its inline Base64 representation:

img.src= "data:image/gif;base64,R0lGODlhCwALAIAAAAAA3pn/ZiH5BAEAAAEALAAAAAALAAsAAAIUhA+hkcuO4lmNVindo7qyrIXiGBYAOw==";


Useful, when you do not intend to publish the page on the web, but instead use it on local machines only.

差↓一点笑了 2024-09-05 23:07:14

面对使用 Javascript 的相同情况。不幸的是,Chrome 不允许访问存储在本地文件中的 JavaScript Worker。

下面使用本地存储的一种解决方法是使用 --allow-file-access-from-files (末尾带有 s)运行 Chrome,但只有一个允许使用 Chrome 实例,这对我来说不太方便。因此,我使用 Chrome Canary,并允许文件访问。

顺便说一句,在 Firefox 中不存在这样的问题。

Faced with the same situation playing with Javascript . Unfortunately Chrome doesn't allow to access javascript workers stored in a local file.

One kind of workaround below using a local storage is to running Chrome with --allow-file-access-from-files (with s at the end), but only one instance of Chrome is allowed, which is not too convenient for me. For this reason i'm using Chrome Canary, with file access allowed.

BTW in Firefox there is no such an issue.

烟燃烟灭 2024-09-05 23:07:14

如果您尝试使用数据 URI 方案创建 Web Worker,则会弹出此错误。

var w = new Worker('data:text/javascript;charset=utf-8,onmessage%20%3D%20function()%20%7B%20postMessage(%22pong%22)%3B%20%7D'); w.postMessage('ping');

根据标准,这是不允许的: http ://www.whatwg.org/specs/web-apps/current-work/multipage/workers.html#dom-worker

This error pops up, if you try to create a web worker with data URI scheme.

var w = new Worker('data:text/javascript;charset=utf-8,onmessage%20%3D%20function()%20%7B%20postMessage(%22pong%22)%3B%20%7D'); w.postMessage('ping');

It's not allowed according to the standard: http://www.whatwg.org/specs/web-apps/current-work/multipage/workers.html#dom-worker

旧人九事 2024-09-05 23:07:14

我在使用历史 API 时遇到了这个问题。

window.history.pushState(null, null, URL);

即使使用本地服务器 (localhost),您也需要将“http://”添加到 URL,以便获得类似于以下内容的内容:

http://localhost...

I had this issue when using the history API.

window.history.pushState(null, null, URL);

Even with a local server (localhost), you want to add 'http://' to your URL so that you have something similar to:

http://localhost...
甜宝宝 2024-09-05 23:07:14

我对 --allow-file-access-from-files 解决方案并不完全满意,因为我使用 Chrome 作为我的主要浏览器,并且对这次违规并不太满意开放。

现在我正在使用 Canary(chrome beta 版本)进行开发,并打开该标志。
而我真正的博客的 Chrome 版本:这两个浏览器不共享标志!

I wasn't completely happy by the --allow-file-access-from-files solution, because I'm using Chrome as my primary browser, and wasn't really happy with this breach I was opening.

Now I'm using Canary ( the chrome beta version ) for my development with the flag on.
And the mere Chrome version for my real blogging : the two browser don't share the flag !

孤独患者 2024-09-05 23:07:14

如果在获得许可之前使用新的(目前仅限 webkit)通知功能,也可能会收到此错误。

首次运行:

<!-- Get permission -->
<button onclick="webkitNotifications.requestPermission();">Enable Notifications</button>

稍后运行:

// Display Notification:
window.webkitNotifications.createNotification('image', 'Title', 'Body').show();

请求权限功能需要由用户引发的事件触发,否则不会显示。

One can also receive this error if using the new (so far webkit only) notification feature before getting permission.

First run:

<!-- Get permission -->
<button onclick="webkitNotifications.requestPermission();">Enable Notifications</button>

Later run:

// Display Notification:
window.webkitNotifications.createNotification('image', 'Title', 'Body').show();

The request permission functions needs to be triggered from an event caused by the user, otherwise it won't be displayed.

甚是思念 2024-09-05 23:07:14

当使用 ASP.NET MVC 返回带有重载的 FileResult 时,我在移动 safari 中遇到了该错误,该重载返回的文件名与原始文件名不同。因此,

return File(returnFilePath, contentType, fileName);

在 mobile safari 中会出现错误,而 as 则

return File(returnFilePath, contentType);

不会。

我什至不记得为什么我认为我正在做的事情是个好主意。我想是想变得聪明吧。

I was been getting that error in mobile safari when using ASP.NET MVC to return a FileResult with the overload that returns a file with a different file name than the original. So,

return File(returnFilePath, contentType, fileName);

would give the error in mobile safari, where as

return File(returnFilePath, contentType);

would not.

I don't even remember why I thought what I was doing was a good idea. Trying to be clever I guess.

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