English 中文(简体)
Close ColorBox iFrame after submit
原标题:

I m using jQuery ColorBox to display a shopping cart item. When a user enters the quantity in the iFrame (opened with colorbox) and clicks on the submit button, I want the iFrame to be close and main window (parent) to be refreshed automatically.

I mean I want two things after submitting data on iFrame:

  1. iFrame closes automatically.
  2. Parent window getting refresh automatically.

Please help me out.

最佳回答

use this on the parent window while opening iframe:

$(document).ready(function(){
    $(".chpic").colorbox({width:"80%", height:"80%", iframe:true, 
        onClosed:function(){ location.reload(true); } });
});

and this to close the iframe inside iframe page:

parent.$.fn.colorbox.close();
问题回答

After the form is submitted in Frame 1, you can use the following JavaScript to reload the parent frame:

window.parent.location.reload(true);
<form target="_top">

open jquery.colorbox.js find these two pieces of code:

$close.click(function () {
  publicMethod.close(); 
});


$overlay.click(function () {
  if (settings.overlayClose) {
    publicMethod.close();
  }
});

replace with these - note the addition of " window.location.reload();"

$close.click(function () {
  publicMethod.close();
  window.location.reload();         
});


$overlay.click(function () {
  if (settings.overlayClose) {
    publicMethod.close();
    window.location.reload();
  }
});

Just simply simulate a click on the close button, like this:

$("#cboxClose").click();

Give form tag like this:

<form target="_top">

then after submit:

response.redirect("your form")

If you re using Drupal 7, you may need to use the following alternative:

parent.jQuery.colorbox.close();

In D7, the $.fn seems to be replaced by the jQuery object.

I simply setup a menu callback which simply returned this:

return <<<EOF
<script type="text/javascript">
  <!--//--><![CDATA[//><!--
  parent.jQuery.colorbox.close();
  //--><!]]>
</script>
EOF;

Seemed to work fine for me :)

If you want to stay on current page :

  1. write the following code on parent page where colorbox is applied.

    $(document).ready(function(){
    
     $(".tu_iframe_800x600").colorbox({width:"80%", height:"100%", iframe:false 
    
      });
    });
    
  2. and the following code on your current page where you want to close colorbox parent.$.fn.colorbox.close();

Note: please replace .tu_iframe_800x600 with your html class on which the colorbox is called...





相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签