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

前端 未结 12 896
逝去的感伤
逝去的感伤 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 19:54

    Refresh or reload on closing the form using fancybox in Shopify

    I was using this on Shopify but this will work on other also

      jQuery(".add-device").fancybox({
        maxWidth  : 970,
        maxHeight : 700,
        fitToView : false,
        width     : '90%',
        height    : '90%',
        autoSize  : false,
        closeClick  : false,
        openEffect  : 'none',
        closeEffect : 'none',
        beforeClose: function() {
          device_has_subs = false;
          $("#mac_address").prop("readonly", false);
        },
        afterClose    : function() {
          window.location.reload(true);
            }
      });
    

    here only afterClose is playing the task we can also write parent instead of window

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

    If just reset the form in shopify then, In shopify sometime $("form")[0].reset() not works so using iteration we can empty the form value

      jQuery(".add-device").fancybox({
        maxWidth  : 970,
        maxHeight : 700,
        fitToView : false,
        width     : '90%',
        height    : '90%',
        autoSize  : false,
        closeClick  : false,
        openEffect  : 'none',
        closeEffect : 'none',
        beforeClose: function() {
          device_has_subs = false;
          $("#mac_address").prop("readonly", false);
          
          var array_element = document.getElementById("form_id");
          if (array_element){
           
            for (i=0; i < array_element.length; i++){
                element = array_element[i].type.toLowerCase();
                switch(element){
                  case "text":
                      array_element[i].value = "";
                      break;
                  case "hidden":
                      array_element[i].value = "";
                      break;
                  case "email":
                      array_element[i].value = "";
                      break;
                  case "checkbox":
                      if(array_element[i].checked){
                        array_element[i].checked = false;
                      }
                      break;
                  case "select-one":
                      array_element[i].selectedIndex = -1;
                      break;
                  case "select-multi":
                      array_element[i].selectedIndex = -1;
                      break;
                  default:
                      break;
              }
    
            }
          
          }
       
        },
      });
    

    form_id is the form id

提交回复
热议问题