【问题标题】:how to get the return value fancybox iframe onclose in codeiginter如何在codeigniter中获取返回值fancybox iframe onclose
【发布时间】:2014-12-23 22:26:35
【问题描述】:

我正在使用 Fancybox V1.3.4。我将表单提交的值返回到父页面时遇到问题。我没有从当前屏幕(子框架)获取值。

添加页面

<div id ="app_fee_list">
     Fee Split/ Payment Details box 
<a id ="new_app_fee" href="<?php echo base_url('updateappraiserpayment/0')?>" ><i style="margin-left:15px;" class="fa fa-plus-square"></i></a>
                     <?php $this->load->view('andersion/appraiser/appraiserfeetemplate'); ?>
                </div>

这里的fancybox代码是这样的

<script>  
    jQuery(document).ready(function(){
        jQuery('#new_app_fee').live('click', function(){ 
            jQuery(this).fancybox({
            'width'             : '60%',
            'height'            : '90%',
            'autoScale'         : false,
            'transitionIn'      : 'none',
            'transitionOut'     : 'none',
            'type'              : 'iframe',
            'onCleanup': function(){
                feeid = jQuery('#appfeeform').contents().find("#app_fee_id").val();
                alert(feeid);return false; // Here value returns Undefined.
               // If the app_fee_id filed is in Add page it will returns.But this field is not in the ADD page. It is in the SUCCESS page.
            },
            'onClosed': function() {
                location.reload();
            }

        });
    }).trigger('click');
    });
    </script> 

它会触发 updateappraiserpayment 页面。提交此表单后,它将重定向到成功页面。

成功页面

<form name = 'appfee1' id='appfeeform' action="<?php echo base_url('updateappraiserpayment/'.$user_id)?>" method='post'>
<div class="col-sm-12">

          <section class="panel">
            <div class="success">Appraiser fee information has been added successfully</div>
             <input type="hidden" name='appraiser_fee_id' id ="app_fee_id" value="3">   
             </form>
            <?php echo $appraiser_fee_id;exit; // Here i get the Inserted Id Value?>

          </section>
        </div>

成功消息也会显示在 iframe 中。关闭 iframe 后,我需要将插入值的值获取到父页面。我也试过这样

$(".fancybox-iframe").contents().find("#app_fee_id").val();

但我无法得到结果。请给我任何解决此问题的建议。提前致谢

【问题讨论】:

    标签: php jquery html codeigniter fancybox


    【解决方案1】:

    您正在尝试从 iframe 页面获取值到父页面,并且在父页面上运行 js 函数。

    我认为要从iframe中获取一个值到父级,你需要在iframe页面中编写一个js代码。

    所以,要从成功页面到父页面获取隐藏字段'app_fee_id'的值,(假设页面加载时填充'app_fee_id'的值),在成功页面,

    jQuery(document).ready(function($) {
        parent.$("#parent_app_fee_id").val($("#app_fee_id").val());
    });
    

    父页面中添加如下代码,

    <input type='hidden' id='parent_app_fee_id' value=''>
    

    并更新'onCleanup'函数的以下行,

    feeid = jQuery('#parent_app_fee_id').val();
    

    【讨论】:

    • 你让我开心..非常感谢。
    • 嘿,我们都在这里互相帮助:)
    【解决方案2】:

    parent.window.document

    示例:

    parent.window.document.getElementById("parentPagetagId").value = 3;//set value for input parent page
    parent.window.document.getElementById("fancybox-wrap").style.display = 'none';//hidden fancybox
    

    我认为它会在这样的 jQuery 中(但没有检查):

    $("#parentPagetagId",parent.window.document).val(3);
    $("#fancybox-wrap",parent.window.document).hide();
    

    【讨论】:

    • 感谢您对 websky 的帮助。我必须在这里分配一个动态字段值。主要问题是我没有从当前屏幕(子框架)获取值。你能帮忙吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-20
    • 1970-01-01
    • 2018-02-09
    • 1970-01-01
    相关资源
    最近更新 更多