2011-05-23 102 views

回答

5

由于Thickbox不是这样写的,所以它有点复杂。但也许你可以使用一些技巧来做到这一点。

这不是推荐的解决方案,但可以“重写”关闭功能。喜欢的东西:

var old_tb_remove = window.tb_remove; 

var tb_remove = function() { 
    old_tb_remove(); // calls the tb_remove() of the Thickbox plugin 
    alert('ohai'); 
}; 

工程\ O/http://jsfiddle.net/8q2JK/1/

+0

感谢您的代码。发现它的一个问题:图片上传thickbox似乎多次调用tb_remove函数,导致我的自定义tb_remove函数中的代码被多次调用。有关如何解决这个问题的任何想法? – 2011-05-25 10:36:09

+0

嗯......我会尽力找到解决的办法。如果我找到了一些东西,会发表评论...顺便说一句你可以使用另一个库吗 – 2011-05-25 10:56:06

+0

我有一些代码在WordPress这里重现问题:[链接](http://wordpress.stackexchange.com/questions/18216/issue-with-code-manipulating-the-image-upload-thickbox)。我试图使用WordPress的内置图片上传器thickbox,但我遇到了这个问题。 – 2011-05-25 11:04:23

1

认为你可以破解,通过点击处理程序绑定到关闭按钮:

$("#TB_closeWindowButton").click(function() { 
    doSomething(); 
}); 

如果你有一个选择,摆脱thickbox(因为它不再维护),并使用更活跃的社区。厚实网站,其实proposes some alternativesmirror

+1

我想过告诉他,但他必须重新绑定用于关闭厚盒子的所有元素(关闭按钮,覆盖和espace按键上的点击) – 2011-05-23 01:41:03

+0

,但在备选方案上为+1 – 2011-05-23 01:41:13

+0

Ah - 我应该发现这一点。如果感兴趣,我从这里获得了关闭按钮点击处理程序的想法:http:// designerfoo。com/jquery-thickbox-hack-to-refresh-parent-window-on-tb_close-event.html – karim79 2011-05-23 01:46:19

-1

您可以将侦听器绑定到在关闭thickbox时触发的“tb_unload”。例如使用jQuery:

<input id="tb_button" type="button" value="Click to open thickbox" /> 

jQuery('#tb_button').on('click', function(){ 
     tb_show('This is Google in a thickbox', 'http://www.google.com?TB_iframe=true'); 
     jQuery('#TB_window').on("tb_unload", function(){ 
     alert('Triggered!'); 
    }); 
} 
+0

这实际上是一个很好的答案。但是,tb_unload不是指向thickbox主页的源代码中的函数。但它是在WordPress的版本。指出这可能会有所帮助。而且,它是触发thickbox的'a'元素,而不是输入元素。最后,这个例子不起作用,因为Google禁止以这种方式加载.tb_unload事件。也许是一个jsfiddle或codepen的例子。 – 2016-01-04 02:41:06

0

在ThickBox的3.1, 我会去的ThickBox-fixed.js 内将增加一个自定义函数为自己

只是增加一个回调函数,不知道是个好方式,但它的工作为我的项目。

function mycustom_tb_remove(callback) { 
    $("#TB_imageOff").unbind("click"); 
    $("#TB_closeWindowButton").unbind("click"); 
    $("#TB_window").fadeOut("fast",function(){ 
    if(callback)callback(); 
    $('#TB_window,#TB_overlay,#TB_HideSelect').trigger("unload").unbind().remove(); 
    }); 
    $("#TB_load").remove(); 
    if (typeof document.body.style.maxHeight == "undefined") {//if IE 6 
    $("body","html").css({height: "auto", width: "auto"}); 
    $("html").css("overflow",""); 
    } 
    document.onkeydown = ""; 
    document.onkeyup = ""; 
    return false; 
} 

所以,当我用我的自定义删除的功能。我会用这种方式。

​​
2

你可以尝试这样的事情......

var tb_unload_count = 1; 
$(window).bind('tb_unload', function() { 
    if (tb_unload_count > 1) { 
     tb_unload_count = 1; 
    } else { 
     // do something here 
     tb_unload_count = tb_unload_count + 1; 
    } 
}); 

tb_unload被触发,从而两次,这包括一个黑客位,以确保您的代码不运行第二次。