开发者

How can I close a SimpleModal dialog when the user clicks the Back button?

When a user clicks on a button or link, I use the SimpleModal jQuery plugin to display a dialog to overlay the entire page, preventing the user from clicking another button or link during the delay before the next page loads. (I'd like to avoid this, but that's an issue for another day.)

After the next page displays, if the user clicks the Back button, the previous page still has the SimpleModal overlay displayed, preventing them from using the page. This is a problem.

How can I cause the SimpleModal dialog to close automatically either when the leaves the page or when开发者_如何学C the user clicks the Back button to return to the page?

I tried this without success:

$("body").unload(function() {
    $.modal.close();
});

Thanks!

Wally

Update: Here's the solution that seems to work the best:

$(window).bind("beforeunload", function() {
    $.modal.close();
});


Try using:

$(window).unload(function() {
   $.modal.close();
});


Why not just

$.modal.close();

in your $(document).ready()? It shouldn't already be open if it's the user's first time to the page, and if it is, it will be closed automatically. If you have a certain condition under which you want the modal to be open when the person loads the page, just set that by doing a conditional if{} check.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜