Fancy Box - how to refresh parent page when close iframe popup?

前端 未结 12 828
逝去的感伤
逝去的感伤 2020-12-28 19:16

I want my parent page to refresh when I close a Fancy Box popup frame. I have a login page inside the popup, so I need the parent page to refresh to show the new login state

相关标签:
12条回答
  • 2020-12-28 20:01

    Well I know this is an extremely old post but here's a newer answer that I hope helps someone out there. I am using fancybox on a page with my website inquiries to pop up in a lightbox to read / delete. When I delete an inquiry in the light box I wanted the parent to refresh to show a current list of inquiries minus the one I just deleted. The upvoted comment didn't help me (as it is probably referencing an older version of the JS file).

    On line 105 of jquery.fancybox.js (v3.5.7) change:

    afterClose: n.noop,
    

    to

    afterClose: function() {parent.location.reload(true);},
    

    It's been irritating me for a few days but it now works no worries.

    0 讨论(0)
  • 2020-12-28 20:06

    Besides the obvious missing , which you say you have fixed IMO this is not a fancybox issue but rather a parent refresh issue.

    I have found it to be a challenge to get a parent of a frame to reload as there are multiple ways to "theoretically" achieve this but "most" simply do NOT work in practice and worse yet there really doesn't appear to be any error raised by the web browsers I tested with.

    Here is code that works well for me on Chrome, FF, IE:

    afterClose: function(){
        parent.location.href = parent.location.href;
    },
    

    This basically says set the parent href to whatever it is currently which in effect results in a page refresh. Try it out and it should work well.

    In fact the line:

    parent.location.href = parent.location.href;
    

    can be used with frames (from the parent of course) or without frames to simply refresh a web page. HTH.

    0 讨论(0)
  • 2020-12-28 20:07

    link refresh:

    jQuery(function($){ 
        $('#refresh').click(function ()
            {      
                parent.location.reload();
        });
    });
    
    <a href="#" id="refresh">refresh</a>
    

    you can give:

    setTimeout(function () {
                parent.location.reload(); 
            }, 1000);
    

    or condition, for example,

    <script>
    if(formSend == true){
    setTimeout(function () {
                    parent.location.reload(); 
                }, 1000);
    }
    </script>
    
    0 讨论(0)
  • 2020-12-28 20:12
    'onClosed' : function() { parent.location.reload(true); }
    
    0 讨论(0)
  • 2020-12-28 20:13
    $(".fancybox").fancybox({
                'width'             : '75%',
                'height'            : '65%',
                'autoScale'         : false,
                'transitionIn'      : 'none',
                'transitionOut'     : 'none',
                'type'              : 'iframe',
                'hideOnOverlayClick': false,
                'onClosed'          : function() {
                                      parent.location.reload(true);
                                      }
            });
    
    0 讨论(0)
  • 2020-12-28 20:13

    When using the examples with 'location.reload' you get a browser pop that lets you know it needs to reload the page. I fired a button click to refresh the page and no warning popup.

    $(".addDoc").colorbox({
        iframe: true, 
        width: "550px", 
        height: "230px",
        'onClosed': function() {
            $("#btnContSave").click();
        }
    });
    
    0 讨论(0)
提交回复
热议问题