Refreshing the main page after closing a modal window
On a given webpage I have a link开发者_Python百科 that opens a modal window using Thickbox. In that window I have a form which I use to save some data. After I submit the form, I close the modal window. Now my question is: can I refresh the main page after closing the modal window?
Thank you.
Call this after the form is submitted and before the window is closed:
window.opener.location.reload();
Suppose this is the div you show in modal mode. You have to call tb_remove()
to close the modal window. So just use location.reload();
before that call.
<div id="modalContent" style="display:none">
<form>
...
</form>
<p style="text-align:center">
<input type="submit" id="Login"value="Click to close"
onclick="window.opener.location.reload();tb_remove()" />
</p>
</div>
Actually Thickbox is no longer being maintained, so it might be better to use a different modal window. That being said, I know Facebox allows you to bind box open and close events like this:
$(document).bind('close.facebox', function() {
// do something here
})
If using facebox simply add window.location.reload(); around line 148, so you end up with something like... close: function() { $(document).trigger('close.facebox'); window.location.reload(); return false }
If still using Thickbox I'm sure it's just as easy. Do a search for "close" and add the code.
You can do this easily with the tinybox plugin:
http://sandbox.scriptiny.com/tinybox2/
var parentWindow = window;
$('#submit-deed-button').click(function() {
TINY.box.show({iframe:'submit_deed.html', closejs:function(){parentWindow.location.reload()}, post:'id=16',width:385,height:470,opacity:20,topsplit:3, boxid:'tinybox_container'})
});
The key is to pass in the parent window to the function as a JS var then you call location.reload() on that object
精彩评论