【发布时间】:2014-04-10 09:26:20
【问题描述】:
我在一个网站上使用奇妙的 Magnific Popup 脚本来显示图片库。
该网站还支持 apple-mobile-web-app-capable 在 iPad 和 iPhone 上全屏查看。
我正在使用保持独立脚本 (https://gist.github.com/irae/1042167) 来防止在页面之间导航时被转储回 Mobile Safari:
(function(document,navigator,standalone) {
// prevents links from apps from oppening in mobile safari
// this javascript must be the first script in your <head>
if ((standalone in navigator) && navigator[standalone]) {
var curnode, location=document.location, stop=/^(a|html)$/i;
document.addEventListener('click', function(e) {
curnode=e.target;
while (!(stop).test(curnode.nodeName)) {
curnode=curnode.parentNode;
}
// Condidions to do this only on links to your own app
// if you want all links, use if('href' in curnode) instead.
if(
'href' in curnode && // is a link
(chref=curnode.href).replace(location.href,'').indexOf('#') && // is not an anchor
( !(/^[a-z\+\.\-]+:/i).test(chref) || // either does not have a proper scheme (relative links)
chref.indexOf(location.protocol+'//'+location.host)===0 ) // or is in the same protocol and domain
) {
e.preventDefault();
location.href = curnode.href;
}
},false);
}
})(document,window.navigator,'standalone');
此脚本可防止在 iOS 上处于全屏模式时触发 Magnific Popup。我的 Magnific Popup 初始化脚本如下:
jQuery(document).ready(function($) {
$('.lightview').magnificPopup({
type: 'image',
removalDelay: 500,
gallery:{
enabled:true,
},
image: {
verticalFit: true,
titleSrc: function(item) {
return '<strong>' + item.el.attr('title') + '</strong>' + ' <br /><span class="lightbox-caption">' + item.el.attr('data-caption') + '</span>';
},
markup: '<div class="mfp-figure">'+
'<div class="mfp-close"></div>'+
'<div class="mfp-img"></div>'+
'<div class="mfp-title-holder">'+
'<div class="mfp-title"></div>'+
'</div>'+
'<div class="mfp-bottom-bar">'+
'<div class="mfp-counter"></div>'+
'</div>'+
'</div>'
},
callbacks: {
beforeOpen: function() {
this.st.image.markup = this.st.image.markup.replace('mfp-figure', 'mfp-figure mfp-with-anim');
this.st.mainClass = this.st.el.attr('data-effect');
}
},
cursor: 'mfp-zoom-out-cur',
closeOnContentClick: false,
midClick: true
});
});
如何阻止 Stay Standalone 干扰 Magnific Popup?
我在我网站的其他地方有一个自动打开的 Magnific Popup,它不受此影响,它似乎只是通过单击链接调用的弹出窗口......
提前感谢您的帮助!
【问题讨论】:
标签: ios iphone popup magnific-popup