Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Refresh page when colorbox is closed

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? :(

like image 975
Jayyrus Avatar asked Feb 03 '12 13:02

Jayyrus


2 Answers

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); 
}
like image 94
ScottE Avatar answered Nov 03 '22 11:11

ScottE


You can also put the refresh within the originating call for the colorbox

$(document).ready(function(){
    $('.iframe').colorbox({
        iframe:true,
        width:'700px',
        height:'800px',
        onClosed:function(){ location.reload(true); },
    }); 
});
like image 4
Warren Landis Avatar answered Nov 03 '22 11:11

Warren Landis