gpt4 book ai didi

magnific-popup - 如何让浏览器返回关闭 magnific-popup

转载 作者:行者123 更新时间:2023-12-04 06:37:42 25 4
gpt4 key购买 nike

我的弹出窗口正常工作,但有时用户会点击浏览器上的后退按钮关闭弹出窗口。

如何让浏览器后退按钮关闭已经打开的“magnific-popup”?

谢谢

最佳答案

经过一些挖掘发现 history.js 然后是下面的

var magnificPopup = null;
jQuery(document).ready(function ($) {
var $img = $(".img-link");
if ($img.length) {
$img.magnificPopup({
type: 'image',
preloader: true,
closeOnContentClick: true,
enableEscapeKey: false,
showCloseBtn: true,
removalDelay: 100,
mainClass: 'mfp-fade',
tClose: '',
callbacks: {
open: function () {
History.Adapter.bind(window, 'statechange', closePopup);
History.pushState({ url: document.location.href }, document.title, "?large");
$(window).on('resize', closePopup);
magnificPopup = this;
},
close: function () {
$(window).unbind('statechange', closePopup)
.off('resize', closePopup);
var State = History.getState();
History.replaceState(null, document.title, State.data["url"]);
magnificPopup = null;
}
}
});
}
});

function closePopup () {
if (magnificPopup != null)
magnificPopup.close();
}

关于magnific-popup - 如何让浏览器返回关闭 magnific-popup,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22229689/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com