您好,感谢您对此的任何支持。
我有一个网站可供美国访问者登陆美国非盟网站时通过Modal弹出窗口将其送回美国特定网站。
我只希望脚本每次访问运行一次。
要实现此目的,我需要在下面添加什么?
谢谢(ps-对于ajax和HTML / CSS以外的任何事物来说都是非常新的东西)
$(document).ready(function() {
$.ajax({
url: 'https://api.ipstack.com/check?access_key=##hidden##',
dataType: 'jsonp',
success: function(location) {
// AU -- Australia
if (location.country_code === 'AU') {
} else {
// Reveal Modal to select AU or US store
// Modal 1
$('#popup-2').slickModals({
popupType: 'delayed',
delayTime: 0,
overlayColor: 'rgba(0, 0, 0, 0.1)',
popupWidth: '420px',
popupHeight: 'auto',
popupLocation: 'topCenter',
popupAnimationDuration: '0.4',
popupAnimationEffect: 'slideTop',
popupMargin: '30px',
popupPadding: '20px',
mobileBreakPoint: '420px',
mobileLocation: 'topCenter',
mobileWidth: '100%',
mobileHeight: 'auto',
mobilePadding: '0px',
reopenClass: 'openSlickModal-2'
})
}
}
});
});
答案 0 :(得分:0)
假设“访问” 是在选项卡/浏览器关闭时结束的任何浏览器会话,则可以使用sessionStorage
来存储标志。
例如
if (!sessionStorage.getItem('redirect-offered')) {
$.ajax(...)
}
以及您的成功处理程序
if (location.country_code === 'AU') {
} else {
// the value doesn't really matter, it just has to be "truthy"
sessionStorage.setItem('redirect-offered', 1);
$('#popup-2').slickModals(...)
}
此处有完整的代码示例〜https://pastebin.com/X7Jy7BD2