Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript JQuery模态框和Iframe_Javascript_Jquery_Iframe_Refresh_Modal Dialog - Fatal编程技术网

Javascript JQuery模态框和Iframe

Javascript JQuery模态框和Iframe,javascript,jquery,iframe,refresh,modal-dialog,Javascript,Jquery,Iframe,Refresh,Modal Dialog,我一直在使用Simple Modal,我觉得它不符合我目前的需要 <iframe> scrolling="auto" height="100%" frameborder="0" width="100%" title="Dialog Title" marginheight="0" marginwidth="0" id="modalIFrame"

我一直在使用Simple Modal,我觉得它不符合我目前的需要

<iframe> 
       scrolling="auto" 
       height="100%" 
       frameborder="0" 
       width="100%" 
       title="Dialog Title" 
       marginheight="0" 
       marginwidth="0" 
       id="modalIFrame"
       src="test.php" 
</iframe>
是否有支持加载外部文件的模式框,并允许这些外部文件关闭模式框并将父页面重定向到某个url

<iframe> 
       scrolling="auto" 
       height="100%" 
       frameborder="0" 
       width="100%" 
       title="Dialog Title" 
       marginheight="0" 
       marginwidth="0" 
       id="modalIFrame"
       src="test.php" 
</iframe>
我想做的一个例子。您有一个用户列表,您可以单击“添加用户”,然后弹出一个带有表单的模式框,您可以填写并提交它。这将关闭该框并重新加载用户列表页面,以便在列表中看到用户

<iframe> 
       scrolling="auto" 
       height="100%" 
       frameborder="0" 
       width="100%" 
       title="Dialog Title" 
       marginheight="0" 
       marginwidth="0" 
       id="modalIFrame"
       src="test.php" 
</iframe>
然后你可以点击“编辑用户”,一个在表单字段中填写用户信息的模式框会弹出,你可以编辑、提交,它会关闭并刷新

<iframe> 
       scrolling="auto" 
       height="100%" 
       frameborder="0" 
       width="100%" 
       title="Dialog Title" 
       marginheight="0" 
       marginwidth="0" 
       id="modalIFrame"
       src="test.php" 
</iframe>
我知道,如果我将用户信息表单作为每个用户的隐藏div,这是可以做到的,但这不会很好地扩展,而且这是大量开销数据

<iframe> 
       scrolling="auto" 
       height="100%" 
       frameborder="0" 
       width="100%" 
       title="Dialog Title" 
       marginheight="0" 
       marginwidth="0" 
       id="modalIFrame"
       src="test.php" 
</iframe>
我找到了一些,但就是不能让它工作(可能是不同的简单模式版本)

<iframe> 
       scrolling="auto" 
       height="100%" 
       frameborder="0" 
       width="100%" 
       title="Dialog Title" 
       marginheight="0" 
       marginwidth="0" 
       id="modalIFrame"
       src="test.php" 
</iframe>
我也愿意换成另一个模态盒工具

<iframe> 
       scrolling="auto" 
       height="100%" 
       frameborder="0" 
       width="100%" 
       title="Dialog Title" 
       marginheight="0" 
       marginwidth="0" 
       id="modalIFrame"
       src="test.php" 
</iframe>
更新:

<iframe> 
       scrolling="auto" 
       height="100%" 
       frameborder="0" 
       width="100%" 
       title="Dialog Title" 
       marginheight="0" 
       marginwidth="0" 
       id="modalIFrame"
       src="test.php" 
</iframe>
Thickbox或Fancybox是否支持从子IFrame元素关闭?

您尝试过吗?

也是另一个选项。工作原理与Thickbox类似

<iframe> 
       scrolling="auto" 
       height="100%" 
       frameborder="0" 
       width="100%" 
       title="Dialog Title" 
       marginheight="0" 
       marginwidth="0" 
       id="modalIFrame"
       src="test.php" 
</iframe>
编辑:

<iframe> 
       scrolling="auto" 
       height="100%" 
       frameborder="0" 
       width="100%" 
       title="Dialog Title" 
       marginheight="0" 
       marginwidth="0" 
       id="modalIFrame"
       src="test.php" 
</iframe>
经过一番尝试后,该插件似乎不支持通过子iframe元素关闭Fancybox。我认为这当然是可以通过一点努力实现的(我开始一起破解一些东西,虽然我强调这只是一个POC,不起作用,因为iframe中的按钮从DOM中删除了fancybox div包装,因此在再次单击google图像时不会显示)。但是,我想知道iframe是否是正确的选择

<iframe> 
       scrolling="auto" 
       height="100%" 
       frameborder="0" 
       width="100%" 
       title="Dialog Title" 
       marginheight="0" 
       marginwidth="0" 
       id="modalIFrame"
       src="test.php" 
</iframe>
对于添加用户,我的想法是,您可以向用户提供一个模式表单,如单击add user(添加用户)时的表单,对数据源进行AJAX调用以插入新用户,然后在返回成功后,您可以启动页面刷新或使用AJAX更新列表

<iframe> 
       scrolling="auto" 
       height="100%" 
       frameborder="0" 
       width="100%" 
       title="Dialog Title" 
       marginheight="0" 
       marginwidth="0" 
       id="modalIFrame"
       src="test.php" 
</iframe>
对于编辑用户,选择用户后,可以使用用户id进行AJAX调用,以便在AJAX调用返回成功时使用从数据源检索到的用户详细信息填充模式表单。编辑完用户后,进行AJAX调用以更新数据源,然后再次启动页面刷新或使用AJAX进行upd我吃了名单

<iframe> 
       scrolling="auto" 
       height="100%" 
       frameborder="0" 
       width="100%" 
       title="Dialog Title" 
       marginheight="0" 
       marginwidth="0" 
       id="modalIFrame"
       src="test.php" 
</iframe>

不必在每个场景中进行页面刷新或最后的AJAX调用,您只需使用JavaScript/jQuery来更新列表/列表详细信息,具体取决于是否分别添加或编辑了用户。

我找到了解决方案,它使用nyroModal。它支持iframe并通过其iframe子级与thi关闭模式s代码

parent.$.nyroModalRemove();
<iframe> 
       scrolling="auto" 
       height="100%" 
       frameborder="0" 
       width="100%" 
       title="Dialog Title" 
       marginheight="0" 
       marginwidth="0" 
       id="modalIFrame"
       src="test.php" 
</iframe>

我将接受Russ Cam的回答,给他更多的代表性,因为他的回答让我思考了很多这将如何工作,并最终让我找到了答案。

听起来你已经找到了答案,但为了其他人的利益,你可以通过在iFrame中使用以下JavaScript关闭FancyBox的iFrame实现:

parent.$.fn.fancybox.close();
<iframe> 
       scrolling="auto" 
       height="100%" 
       frameborder="0" 
       width="100%" 
       title="Dialog Title" 
       marginheight="0" 
       marginwidth="0" 
       id="modalIFrame"
       src="test.php" 
</iframe>

parent.$.modal.close();
适用于简单模式插件。

下面是一个基本的对话框交互,将内容加载到iFrame中,然后从iFrame关闭对话框

<iframe> 
       scrolling="auto" 
       height="100%" 
       frameborder="0" 
       width="100%" 
       title="Dialog Title" 
       marginheight="0" 
       marginwidth="0" 
       id="modalIFrame"
       src="test.php" 
</iframe>
请注意,为了说明这一点,我有两个代码段。第一个代码段标记为file1.html。第二个代码段如果希望它工作并将其放置在与第一个文件相同的目录中,则应命名为“myPage.html”

<iframe> 
       scrolling="auto" 
       height="100%" 
       frameborder="0" 
       width="100%" 
       title="Dialog Title" 
       marginheight="0" 
       marginwidth="0" 
       id="modalIFrame"
       src="test.php" 
</iframe>
请注意,根据所需的功能,关闭对话框的调用可用于其他方式。例如,另一个示例可能是成功提交表单

<iframe> 
       scrolling="auto" 
       height="100%" 
       frameborder="0" 
       width="100%" 
       title="Dialog Title" 
       marginheight="0" 
       marginwidth="0" 
       id="modalIFrame"
       src="test.php" 
</iframe>
在系统上本地创建文件,打开file1.html并试用

<iframe> 
       scrolling="auto" 
       height="100%" 
       frameborder="0" 
       width="100%" 
       title="Dialog Title" 
       marginheight="0" 
       marginwidth="0" 
       id="modalIFrame"
       src="test.php" 
</iframe>
file1.html

<html>
    <head>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js"></script>
    <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.0/themes/base/jquery-ui.css"/>
    <script type="text/javascript">
      $(document).ready(function() {
            $("#modalDiv").dialog({
                modal: true,
                autoOpen: false,
                height: '180',
                width: '320',
                draggable: true,
                resizeable: true,   
                title: 'IFrame Modal Dialog'
            });
            $('#goToMyPage').click(
                function() {
                    url = 'myPage.html';
                    $("#modalDiv").dialog("open");
                    $("#modalIFrame").attr('src',url);
                    return false;
            });                 
      });
    </script>
    </head>
    <body>
        <a id="goToMyPage" href="#">Go to My Page</a>
        <div id="modalDiv"><iframe id="modalIFrame" width="100%" height="100%" marginWidth="0" marginHeight="0" frameBorder="0" scrolling="auto" title="Dialog Title"></iframe></div>
    </body>
</html>
<html>
    <head>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
    <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.0/themes/base/jquery-ui.css"/>
    <script type="text/javascript">
        $(document).ready(function() {
            $('#clickToClose').click(
                function() {
                    window.parent.$("#modalDiv").dialog('close');
                    return false;
            });
            // uncomment and use the below line close when document is ready (no click action by user needed)
            // the same call could be put elsewhere depending on desired functionality (after successful form submit, etc.)
            // window.parent.$("#modalDiv").dialog('close');                    
        });
    </script>
    </head>
    <body>
        <a id="clickToClose" href="#">Click to close.</a>
    </body>
</html>
<iframe> 
       scrolling="auto" 
       height="100%" 
       frameborder="0" 
       width="100%" 
       title="Dialog Title" 
       marginheight="0" 
       marginwidth="0" 
       id="modalIFrame"
       src="test.php" 
</iframe>

$(文档).ready(函数(){
$(“#modalDiv”)。对话框({
莫代尔:是的,
自动打开:错误,
高度:'180',
宽度:'320',
真的,
可调整大小:正确,
标题:“IFrame模态对话框”
});
$(“#转到第页”)。单击(
函数(){
url='myPage.html';
$(#modalDiv”)。对话框(“打开”);
$(“#modalIFrame”).attr('src',url);
返回false;
});                 
});
myPage.html

<html>
    <head>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js"></script>
    <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.0/themes/base/jquery-ui.css"/>
    <script type="text/javascript">
      $(document).ready(function() {
            $("#modalDiv").dialog({
                modal: true,
                autoOpen: false,
                height: '180',
                width: '320',
                draggable: true,
                resizeable: true,   
                title: 'IFrame Modal Dialog'
            });
            $('#goToMyPage').click(
                function() {
                    url = 'myPage.html';
                    $("#modalDiv").dialog("open");
                    $("#modalIFrame").attr('src',url);
                    return false;
            });                 
      });
    </script>
    </head>
    <body>
        <a id="goToMyPage" href="#">Go to My Page</a>
        <div id="modalDiv"><iframe id="modalIFrame" width="100%" height="100%" marginWidth="0" marginHeight="0" frameBorder="0" scrolling="auto" title="Dialog Title"></iframe></div>
    </body>
</html>
<html>
    <head>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
    <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.0/themes/base/jquery-ui.css"/>
    <script type="text/javascript">
        $(document).ready(function() {
            $('#clickToClose').click(
                function() {
                    window.parent.$("#modalDiv").dialog('close');
                    return false;
            });
            // uncomment and use the below line close when document is ready (no click action by user needed)
            // the same call could be put elsewhere depending on desired functionality (after successful form submit, etc.)
            // window.parent.$("#modalDiv").dialog('close');                    
        });
    </script>
    </head>
    <body>
        <a id="clickToClose" href="#">Click to close.</a>
    </body>
</html>
<iframe> 
       scrolling="auto" 
       height="100%" 
       frameborder="0" 
       width="100%" 
       title="Dialog Title" 
       marginheight="0" 
       marginwidth="0" 
       id="modalIFrame"
       src="test.php" 
</iframe>

$(文档).ready(函数(){
$(“#单击关闭”)。单击(
函数(){
window.parent.$(“#modalDiv”).dialog('close');
返回false;
});
//当文档准备就绪时,取消注释并使用下面的行关闭(用户无需单击操作)
//根据所需的功能(成功提交表单后等),可以将相同的调用放在其他位置
//window.parent.$(“#modalDiv”).dialog('close');
});

我的FrameDialog将允许这样做,它基本上是在对话框上扩展的…如果您使用的是同一个域,您应该能够调用$.FrameDialog.close()。但是,如果您正在重定向,您可以简单地重定向父对象。window.parent.location就可以了

<iframe> 
       scrolling="auto" 
       height="100%" 
       frameborder="0" 
       width="100%" 
       title="Dialog Title" 
       marginheight="0" 
       marginwidth="0" 
       id="modalIFrame"
       src="test.php" 
</iframe>
你好,
<iframe> 
       scrolling="auto" 
       height="100%" 
       frameborder="0" 
       width="100%" 
       title="Dialog Title" 
       marginheight="0" 
       marginwidth="0" 
       id="modalIFrame"
       src="test.php" 
</iframe>
使用Wordpress 3.0中的Fancy Box手动安装关闭Fancy Box iFrame时遇到问题的任何人:

<iframe> 
       scrolling="auto" 
       height="100%" 
       frameborder="0" 
       width="100%" 
       title="Dialog Title" 
       marginheight="0" 
       marginwidth="0" 
       id="modalIFrame"
       src="test.php" 
</iframe>
在iframe中使用此链接:

<a href="#" onClick="parent.jQuery.fancybox.close();" title="Close window">close fancybox</a>
<iframe> 
       scrolling="auto" 
       height="100%" 
       frameborder="0" 
       width="100%" 
       title="Dialog Title" 
       marginheight="0" 
       marginwidth="0" 
       id="modalIFrame"
       src="test.php" 
</iframe>


它可以工作:)

这是我用firebug跟踪时对话框的脚本

<iframe> 
       scrolling="auto" 
       height="100%" 
       frameborder="0" 
       width="100%" 
       title="Dialog Title" 
       marginheight="0" 
       marginwidth="0" 
       id="modalIFrame"
       src="test.php" 
</iframe>

滚动=“自动”
高度=“100%”
frameborder=“0”
宽度=“100%”
title=“对话框标题”
marginheight=“0”
marginwidth=“0”
id=“modalIFrame”
src=“test.php”
我需要c