Refresh page when colorbox is closed

JackTurky picture JackTurky · Feb 3, 2012 · Viewed 12.3k times · Source

i'm using colorbox and i want to refresh page when it will be closed, so i try something like this:

    $.colorbox({href:"loading.html",title:'send notification...',escKey:false,width:300,height:00,
overlayClose:false,onClosed:location.reload(true)});
                $.ajax({
                   url: "sendNot.php",
                   type: "POST",
                   data: {titolo:titolo.value,messaggio:messaggio.value},
                   success: setTimeout("parent.$.colorbox.close()",5000)
                }); 

if i remove onclosed option, after 5 seconds colorbox will be removed, but doing like code upon it will close when ajax stop to load page in post. What is the problem? can you help me? NO oNE? :(

Answer

ScottE picture ScottE · Feb 3, 2012

Try this:

$.colorbox({href:"loading.html",title:'send notification...',escKey:false,width:300,height:00,
overlayClose:false,onClosed:function() { location.reload(true); }});

Just to clarify the difference - the plugin allows you to supply a callback function for the onClosed event, which must be a named or anonymous function. This is an anonymous function - you could have easily done the following instead, to improve readability / reusability (in some cases). Notice the lack of brackets on the callback.

    $.colorbox({href:"loading.html",title:'send notification...',escKey:false,width:300,height:00,
    overlayClose:false,onClosed:reloadPage});

function reloadPage() {
    location.reload(true); 
}