How to get a callback working with SimpleModal
I've been unable to catch the onclose from within simplemodal. please give me a hand if you can as i'm new to jQuery...
<a href="http://url/" onclick="$(this).modal({width:833, height:453}).open(); return false;">
works, but i would like to call a javascript function whenever the modal dialog is closed. How do i开发者_JAVA技巧 attach, say updateTable(); onto the close event??
I've tried
<a href="" onclick="$(this).modal({onClose: alert(1);$.modal.close();}).open();"
and all stupd variations of this, but honestly looking at the nested functions in the example page only made me dizzy (the second example also has the href, but it doesnt let me post it here)....
If I understand you correctly you want to
- Click on a link (e.g. with id clicker)
- The page defined by the URL in the href of this
<a href="...">
tag should be the modals content - When the user closes the modal you want to trigger some action and close the modal
HTML:
<a href="http://www.google.com" id="clicker">Click me!</a>
JavaScript
var c = function closer() {
$.modal.close();
alert("Done!");
}
$(document).ready(function() {
$("#clicker").click(function() {
$.modal(
'<iframe src="'+this.href+'" width="833" height="453">asd</iframe>',
{onClose:c}
);
return false;
});
});
Check http://jsbin.com/ofimi for a working sample
First you do not have to add the onclick attribute when using jQuery. Assume
<a id="clicker" href="http://url/" >Click</a>
Then
$(document).ready(function(){
$("#clicker").click(function(){
$(this).modal({width:833, height:453, onClose: function(){
//your code here}})
.open();
return false;
});
});
The $(this) reference actually refers to the a tag, maybe you might want to use a div called dialog like this:
<div id="dialog"></div>
and change the jQuery to
$("#dialog").modal(...)
UPDATE: Based on your comment. try this.
<head>
<!-- Include your script tags here to load the jQuery and simplemodal scripts -->
<script type="text/javascript">
$(document).ready(function(){
$("#clicker").click(function(){
$("#dialog").modal({onClose: function(){
alert("Closing");
}
});
return false;
});
});
</script>
</head>
<body>
<div id="dialog"></div>
<a href="#" id="clicker">Click</a>
</body>
精彩评论