如何在beforeShow块中覆盖this.href? (jquery / fancybox)

时间:2012-07-30 06:22:26

标签: javascript jquery fancybox

我正在尝试覆盖this.href块中的beforeShow,但它不起作用。 this.href的旧值即使被覆盖也会被使用。

代码是:

beforeShow: function (opts, fb_obj) {

    // this conditional is some other code checking $(window).width() and $(window).height() and
    // if the bigger image will fit; it is simplified here!
    if (1) {
        var source = this.href;
        this.href = source.replace('_large','_super_large');
        console.log('retina detacted! ' + source + " " + this.href);
        // console output is OK, but this.href is not beeing replaced in the output!
}

2 个答案:

答案 0 :(得分:1)

如果您想覆盖this.href的值,请改用beforeLoad

注意:这适用于fancybox v2.0.6 +

答案 1 :(得分:0)

因为你在jquery中标记了这个..我们说

完整代码

if (1) {
         var oldhref = $(this).attr('href');
        $(this).attr('href','_super_large');
        console.log('retina detacted! ' +oldhref + " " + this.attr('href');
}