如何解决“访问属性的权限被拒绝‘警报’”?
我正在为一个网页制作 greasmonkey 脚本。该页面有多个 iframe。我发现它们是问题所在,但我不知道如何解决该问题。
首先,我的脚本创建了一个带有按钮的小 div 框。通过按下按钮,脚本分析网页内容并在某些条件下调用警报
。
Firefox 中的 Javascript 控制台已经告诉我 document
的访问被拒绝,因为我的脚本正在使用 document.getElementByID
来查找顶部文档的正文,其中附加了 div 框到。
这是很容易避免的问题,因为脚本会失败并卡在 iframe 中,但它仍然在主页上继续,因为它确实提供了对 document
的访问权限。
当我尝试在我的函数中使用警报时,问题就出现了。似乎 iframe 接管了我的脚本,并以访问属性“alert”的权限被拒绝
的方式终止了它。
我如何告诉浏览器/脚本或其他什么,我只希望我的脚本在主文档上运行,并且我不想被 iframe 打扰?我安装了无脚本插件,允许主域并阻止辅助域(即加载到 iframe 中)并且所有警报消息都正常。但是,我不能要求我的用户安装 noscript 启用/禁用特定域,并且我的脚本应该可以正常工作。我需要找到适用于所有启用的 iframe 的解决方案。
希望这听起来没有令人困惑。
感谢您的帮助。
There is a webpage i am making a greasmonkey script for. This page has several iframes. I have found out that they are the problem, however i do not know how to solve the issue.
At first my script creates a small div box with the button. By pressing a button script analyzes webpage contents and calls alert
on certain conditions.
Javascript console in Firefox already shouts to me that access was denied for document
because my script is using document.getElementByID
to find the top document's body, where the div box is being appended to.
This is easily avoidable problem as then script fails and gets stuck in iframes, yet it still continues on the main page as it does give the access to document
.
The problem araises when i try to use alert in my function. Seems like iframes take over my script and kills it with the Permission denied to access property 'alert'
.
How do i tell browser/script or whatever, that i only want my script to run on main document and i do not want to be bothered by iframes?I installed NO-script addon, allowed the primary domain and blocked the secondary domain (that loads inside iframes) and all the alert messages go normal. But, i can't ask my users to install noscript enable/disable specific domains and my script should be working fine. I need to find solution which would work with all the iframes enabled.
Hope it didn't sound confusing.
Thank you for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
关于:
首先,调整包含和排除指令以尽可能忽略 iframe。例如:
接下来,将这两行添加为 元数据块 之后的第一行代码:
这将停止 GM 脚本从 iframe 上运行。
RE:
First, adjust your include and exclude directives to ignore the iframes as much as possible. EG:
Next, add these 2 lines as the first lines of code after the Metadata Block:
That will stop the GM script from running on iframes.