关闭 jQuery 灯箱时执行函数

Execute function when closing jQuery Lightbox

单击关闭灯箱时,我希望该操作将用户重定向到另一个 URL。我怎么会写这样的东西?这行得通吗?

<!DOCTYPE html>
<html>
<body>
$(“p”).click(function(){
   // Close Lightbox URL redirection
   $(this).( location ).attr("href", url);
   url = "put url here";
});
</body>
</html>

这行得通,

<!DOCTYPE html>
<html>
<body>
$(“p”).click(function(){
   // Close Lightbox URL redirection
   url = "put url here";
   $(location).attr('href',url);
});
</body>
</html>

两个更改,将 $(this) 更改为 $(location),因为 $(this) 将有 <p> 元素被单击,而不是 window 对象。 P.S。只要一个 $(location) 就可以了。

其次,将 url = "put url here"; 移动到重定向代码上方,显然在重定向之前有 url 。不这样做会引发错误,因为 url 会是 undefined

要返回,您可以使用,

window.history.back();

您可以使用 lightboxbeforeClose event 来完成此操作。请参阅我为您创建的以下演示:

DEMO

您只需要 jQuery 的以下位:

$('#clickMe').featherlight('.inline', {
    beforeClose: function(event){
        // If you want to open url in other tab:
        window.open("http://www.google.com");
    }
});

此处,url 在另一个选项卡 中打开。如果您想在 相同的选项卡 中打开 url,您可以使用:

location.href = "http://www.google.com";

希望对您有所帮助。祝你好运!