I'm using WP and I use the Thickbox to upload images in the back end on a custom page.
Is there a way for JS to check to see if the Thickbox is open?
I need to check this as I have an onbeforeunload
event (to show a warning when the user leaves the page, in certain situations), but obviously Idon't want the warning shown when the user is just navigating between Thickbox pages. Thanks.
Code I currently use -
var bol_submit_clicked = false;
$('input[name="Submit"]').click(function(){
bol_submit_clicked = true;
});
window.onbeforeunload = function closeEditorWarning(){
var bol_option_changed = false;
/** Check to see if the settings warning is displayed */
if($('#unsaved-settings').css('display') !== 'none'){
bol_option_changed = true;
}
/** Display a warning if the user is trying to leave the page with unsaved settings */
if(bol_option_changed === true && bol_submit_clicked === false){
return '';
}
};
There's no inherent function in Thickbox to check, but looking at the code, you should just be able to check for the presence and visibility of #TB_window
:
var thickbox_shown = ($('#TB_window').is(':visible')) ? true : false;
Or, try counting the length of #TB_load
:
var thickbox_shown = ($('#TB_load').length > 0) ? true : false;\