user860511
user860511

Reputation:

Colorbox not redirecting to my chosen URL

<script>
$(document).ready(function() {  
$('#reset_password').live('click', function(e) { 
    parent.$.fn.colorbox.close(); 
    parent.$(document).bind('cbox_closed', function(){ 
    window.location.href = "search_message_thankyou.php";
        }); 
    });
});  
 </script>

The script closes the colorbox as I need, but then doesn't redirect to the thank you page. I look up whats happening in the console and this is the error:

Uncaught TypeError: Cannot read property 'location' of undefined

Any help would be hugely appreciated.

Many thanks in advance.

Upvotes: 1

Views: 3209

Answers (3)

JustinJason
JustinJason

Reputation: 76

They key is to initiate the bind from the parent page, not from the iframe.

In my own solution I used the example below:

$(document).ready(function(){

    $(".iframe").colorbox({width:"80%", height:"80%", iframe:true});

    if ($('.btn_OpenColorbox').length) {
        //check for existence of colorbox open button
        //bind and redirect after colorbox closes
        $(document).bind('cbox_closed', function () {
            window.location.assign('My-Redirect-Page.aspx');
        });
    }
    $('.btn_CloseColorbox').click(function () {
        //close colorbox
        parent.$.colorbox.close();
    });
}

There's another example here: https://groups.google.com/forum/?fromgroups#!topic/colorbox/jSrZSoW7P3s

Upvotes: 0

Bogdan
Bogdan

Reputation: 44526

If your colorbox is loading content in an iframe then you might want to try

window.parent.location.href = "search_message_thankyou.php";

Upvotes: 1

Alex Turpin
Alex Turpin

Reputation: 47776

Try putting the bind before you close it, like this:

parent.$(document).bind('cbox_closed', function(){ 
window.location.href = "search_message_thankyou.php";
    }); 
});
parent.$.fn.colorbox.close(); 

Alternatively you could do parent.location.href = x.

Upvotes: 0

Related Questions