简体   繁体   English

错误:拒绝访问iFrame中的属性“文档”的权限

[英]Error: Permission denied to access property 'document' in iFrame

I have a parent html page which uses jquery to append a dynamic iframe which has a source to another domain. 我有一个父html页面,该页面使用jquery将动态源iframe附加到另一个域。 I have already set the X-Frame-Options to allow this and loading plain content is not a problem. 我已经设置了X-Frame-Options来允许这样做,并且加载纯内容不是问题。 In fact all my other scripts seem to be working fine. 实际上,我所有其他脚本似乎运行良好。

The html page which loads in the iFrame, uses the jQuery DirtyForms plugin which has several lines which look like $(document) . 在iFrame中加载的html页面使用jQuery DirtyForms插件 ,该插件有几行看起来像$(document) Both the dirty forms code and jQuery scripts are local to the iframe's document. 脏表单代码和jQuery脚本均位于iframe文档的本地。

When the any of these lines executes, I receive the following error in Firefox ( I have not tested any other browsers), Error: Permission denied to access property 'document'. 当这些行中的任何一条执行时,我在Firefox中收到以下错误(我尚未测试任何其他浏览器),错误:拒绝访问属性“文档”的权限。

I have been reading up on this and this seems to be a problem if the parent page is trying to access the child's scripts or visa-versa, but in my case, the scripts that are erring are local to the child. 我一直在阅读,如果父页面试图访问孩子的脚本或反之亦然,这似乎是个问题,但就我而言,犯错的脚本对于孩子来说是本地的。

BTW. 顺便说一句。 The child code, when NOT loaded within the iFrame, works perfectly. 如果未在iFrame中加载子代码,则子代码可以完美运行。

I am at a loss right now to find a work-around. 我现在很茫然,无法找到解决方法。

I assume that $(document) is somehow being evaluated as the parent. 我假设$(document)被作为父级进行评估。

Is there some way of correcting this behavior? 有什么办法可以纠正这种行为? Perhaps by modifying the plug-ins code. 也许通过修改插件代码。 Perhaps, $(document).find('contentWindow')...?? 也许$(document).find('contentWindow')... ??

I appreciate the help! 感谢您的帮助! Thanks. 谢谢。

Well you cant access it..Now the question is why? 好吧,您无法访问它。现在的问题是为什么?

For that just go through below links 为此,只需通过以下链接

Permission denied to access property 'document' 拒绝访问属性“文档”的权限

Error: Permission denied to access property 'document' 错误:拒绝访问属性“文档”的权限

And in ur case if u want to do anything on page load then better use below code for IFrame 而且在您的情况下,如果您想在网页加载时执行任何操作,则最好对IFrame使用以下代码

 <iframe ........ onload='yourFunction( this )'>

In Dirty Forms 1.x, the default behavior attaches event handlers to anchor tags in any parent page that the current page is hosted within. 在Dirty Forms 1.x中,默认行为将事件处理程序附加到承载当前页面的任何父页面中的定位标记。 The code that does that looks like: 这样做的代码如下所示:

$(top.document).on('click', 'a', aBindFn);
$(top.document).on('submit', 'form', formBindFn);

That is, it is attaching event handlers to the window.top.document . 也就是说,它将事件处理程序附加到window.top.document You can turn off that behavior by using: 您可以通过以下方式关闭该行为:

$.DirtyForms.watchParentDocs = false;

In Dirty Forms 2.x, this behavior has been removed because it pertained only to one specific use case of iFrames (hosting the form that used Dirty Forms within an iFrame). 在Dirty Forms 2.x中,此行为已被删除,因为它仅与iFrame的一种特定用例有关(在iFrame中托管使用​​Dirty Forms的表单)。 You can now customize event binding to attach event handlers either to parent (host) pages or to child iFrames as needed by your page, but by default there is no interaction with iFrames. 现在,您可以自定义事件绑定 ,以根据页面的需要将事件处理程序附加到父(宿主)页面或子iFrame,但是默认情况下,不与iFrame进行交互。 This should allow you to be able to work around issues such as this one. 这应该使您能够解决诸如此类的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM