检查Thickbox是否已打开

时间:2013-01-16 15:59:01

标签: javascript thickbox

我正在使用WP,我使用Thickbox在自定义页面的后端上传图像。

JS是否有办法检查Thickbox是否已打开?

我需要检查这个,因为我有一个onbeforeunload事件(在某些情况下,当用户离开页面时显示警告),但显然我不想在用户导航时显示警告在Thickbox页面之间。感谢。

我目前使用的代码 -

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 '';
    }


};

1 个答案:

答案 0 :(得分:2)

要检查Thickbox中没有固有的功能,但查看代码,您应该能够检查#TB_window的存在和可见性:

var thickbox_shown = ($('#TB_window').is(':visible')) ? true : false;

或者,尝试计算#TB_load的长度:

var thickbox_shown = ($('#TB_load').length > 0) ? true : false;\
相关问题