标签: jquery-dirtyforms

错误:在iFrame中访问属性"文档"的权限被拒绝

我有一个父html页面,它使用jquery附加一个动态iframe,它有一个源到另一个域.我已经设置了X-Frame-Options来允许这个并且加载普通内容不是问题.事实上,我所有其他脚本似乎都运行正常.

在iFrame中加载的html页面使用jQuery DirtyForms插件,该插件有几行看起来像$(document).脏表单代码和jQuery脚本都是iframe文档的本地代码.

当这些行中的任何一行执行时,我在Firefox中收到以下错误(我没有测试任何其他浏览器),错误:访问属性"文档"的权限被拒绝.

我一直在阅读这一点,如果父页面试图访问孩子的脚本或反之亦然,这似乎是一个问题,但在我的情况下,错误的脚本是孩子的本地脚本.

BTW.子代码在未加载到iFrame中时,可以很好地工作.

我现在无法找到解决办法.

我假设$(document)以某种方式被评估为父级.

有没有办法纠正这种行为?也许通过修改插件代码.也许,$(document).find('contentWindow')...... ??

我很感激帮助!谢谢.

iframe jquery cross-domain jquery-dirtyforms

8
推荐指数
1
解决办法
3万
查看次数

使用JQuery DirtyForms插件的示例

我正在使用jQuery DirtyForms插件来防止用户无意中离开页面而不保存.我在对话框中遇到了一些麻烦.我有两个按钮:取消和不保存.

"取消"操作正常工作:对话框关闭,未加载新页面.但是,"不保存"操作无效.应该加载新页面,但它没有发生.

我一定错过了一些明显的东西.谁能看到我做错了什么?

<script type="text/javascript">

    $(document).ready(function(){
            $('form').dirtyForms();
    });

    $('a').click(function(event){
            event.preventDefault();
            var targetUrl = $(this).attr("href");

            if($.DirtyForms.isDirty()){
                    $("#dialog-savechanges").dialog({
                            height: 250,
                            width: 500,
                            modal: true,
                            buttons: {
                                    Cancel: function() {
                                            $( this ).dialog( "close" );
                                            $.DirtyForms.choiceContinue = false;
                                            $.DirtyForms.choiceCommit(event);
                                    },
                                    "Don't Save": function() {
                                            $( this ).dialog( "close" );
                                            $.DirtyForms.choiceContinue = true;
                                            $.DirtyForms.choiceCommit(event);
                                    }
                            }
                    });
            }
    });

</script>

<div id="dialog-savechanges" title="Save Changes?">
    <p>You've made changes to this page. Do you want to leave this page without saving?</p>
</div>
Run Code Online (Sandbox Code Playgroud)

谢谢!

史蒂夫

jquery jquery-plugins jquery-dirtyforms

3
推荐指数
1
解决办法
3652
查看次数