0

I want to prevent closing the colorbox accidentally so I'll be showing/hiding the close button from inside the loaded iframe.

I read the documentation but both examples don't seem to work:

var originalClose = $.colorbox.close;
$.colorbox.close = function(){
    var response;
    if($('#cboxLoadedContent').find('form').length > 0){
        response = confirm('Do you want to close this window?');
        if(!response){
            return; // Do nothing.
        }
    }
    originalClose();
};

or

<!-- calling colorbox's close method from within an iframe: -->
<a href='#' onclick='parent.$.colorbox.close(); return false;'>close this iframe</a>

... the colorbox just doesn't close. What am I doing wrong?

in the console I see:

Uncaught TypeError: Cannot read property 'colorbox' of undefined 

Thanks!

eozzy
  • 66,048
  • 104
  • 272
  • 428

3 Answers3

0

It should be:

parent.$('#yourElement').colorbox.close();

Where yourElement would be the ID / Selector of the iframe containing the colorbox.

axel.michel
  • 5,764
  • 1
  • 15
  • 25
  • iframe containing the lightbox? Its the lightbox containing the iframe, and iframe has NO ID – eozzy Feb 02 '13 at 14:47
0

You need to include colorbox.css and jquery.colorbox.js after jquery library.

Your first example overrides colorbox close function and second example just closing colorbox.

$('#cboxLoadedContent').find('form')

In my example I don't have form, so I remove form selector.

Demo: http://jsfiddle.net/BY3ZK/

Colorbox is just div, not iframe, so I remove parent from here:

parent.$.colorbox.close();

Demo: http://jsfiddle.net/BY3ZK/1/

webdeveloper
  • 17,174
  • 3
  • 48
  • 47
0

Try using $('#cboxClose').remove(); to close the colorbox

Rahul Singh
  • 133
  • 1
  • 2
  • 11