Passing variable from fancybox to parent page when closing fancybox

无人久伴 提交于 2019-12-25 12:11:17

问题


Hi im trying to send a variable from a child iframe fancybox to the parent. But i cant seem to grasp how to do it. Does anyone have a idea. I already tried with js. A friend suggested to do it with php but havent find a solution. I have a mess right now. I tried another questions answers similar to mine with no luck. Here is the code this is in the fancybox:

 <script type="text/javascript">
    function OnClickButton (nombre) {

        parent.$.nombre(nombre);
        parent.$.fancybox.close();

    }
</script>

<?php foreach($files1 as $file): ?>
                <?php if ($cont>1) { ?>
                  <li>

                        <a onclick="OnClickButton ('<?php echo $file;?>');" href="<?php echo $file;?>"><img style="width: 50px;" 
                            src="img/folderImg.png"></a>

                  </li>
                <?php } ?>
              <?php $cont++; endforeach ?>

This is in the parent page

function nombre (nombre) {

        name = nombre;
        alert(nombre)

    }
    $(document).ready(function() {
        $(".fancybox").fancybox();
    });
    $(document).ready(function() {
    $(".various").fancybox({
        maxWidth    : 800,
        maxHeight   : 400,
        fitToView   : false,
        width       : '70%',
        height      : '70%',
        autoSize    : false,
        closeClick  : false,
        openEffect  : 'none',
        closeEffect : 'none',
        afterClose  :   function() {

            if (name == 'folder 1') {
                $('.fancybox-thumb').fancybox().trigger('click');
            }
            if (name == 'folder 2') {
                $('.fancybox-thumb2').fancybox().trigger('click');
            }
            if (name == 'folder 3') {
                $('.fancybox-thumb3').fancybox().trigger('click');
            }

        }
    });
    });

回答1:


I will try two solution, i don't know if in your case can works but are pretty solid.

1) sessionstorage:

using sessionstorage with jquery you can save a parameter and use it later in any page.

sessionStorage.setItem("nameofthestorage", yourvalue);

and to take the saved info

var x = sessionStorage.getItem("nameofthestorage");

2)save a php session:

i'm a bit rusted with php but you can see this official and easy guide http://www.w3schools.com/php/php_sessions.asp



来源:https://stackoverflow.com/questions/23017624/passing-variable-from-fancybox-to-parent-page-when-closing-fancybox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!