如何制作"Dont ask me again"选项?
How to make a "Dont ask me again" Option?
我正在尝试使用 css3 在我的网站中创建一个对话框,如果用户使用 adblock,该对话框就会弹出。该对话框基本上要求用户在我的网站上启用广告,但我不想每次 he/she 访问我的网站时弹出对话框来打扰用户,所以我想给用户一个 "Dont show me again"选项,但我不知道如何实现它。
这是对话框的图片
这是检测广告拦截用户并打开对话框的java脚本代码
<script> window.setTimeout(function(){
if(adsbygoogle instanceof Array) {
// adsbygoogle.js did not execute; probably blocked by an ad blocker
window.location = '#PleaseUnblock'
} else {
// adsbygoogle.js executed
}
}, 2000);
</script>
这是 html 对话框的代码
<div id="PleaseUnblock" class="modalDialog">
<div style="margin-top: 70px;padding: 5px 12px 13px 15px;width: 380px;">
<a href="#" title="Close" class="close">X</a>
<div style="padding: 0; margin: 0;">
<h1 class="ad-di-title">You Are Using AdBlock :(</h1>
</div>
<div style="margin-left: auto;margin-right: auto;width: 350px;height: 332px;background: url(/assets/please.jpg);background-size: 350px;background-repeat: no-repeat"></div>
<p class="ad-di-para" style="margin-bottom: 3px;">All content made on WEBSITENAME is free. As you use Adblock, we wont get any revenue from the content we make. We promise that we will not show annoying ads and we only ask you to enable ads in our site.</p>
<a style="margin-left: 300px" href="#" class="kbtn">Ok</a>
</div>
</div>
使用 cookie 的相当简单的解决方案:
function askLater() {
var d = new Date();
d.setTime(d.getTime() + (86400000)); //set the time to 24 hours later
var expires = "expires="+d.toUTCString();
document.cookie = "dontAsk=true; " + expires;
}
如果用户按下 "Don't ask me again" 按钮,则调用函数 askLater()
。
然后,在您的代码中测试 cookie dontAsk,例如:
if(adsbygoogle instanceof Array && document.cookie.indexOf("dontAsk") == -1) {
// indexOf is -1 when string not found, so the cookie is unset
// adsbygoogle.js did not execute; probably blocked by an ad blocker
window.location = '#PleaseUnblock'
} else { ... }
如果您不想再询问,请改用此方法:
function neverAsk() {
document.cookie="dontAsk=true";
就这么简单。
我正在尝试使用 css3 在我的网站中创建一个对话框,如果用户使用 adblock,该对话框就会弹出。该对话框基本上要求用户在我的网站上启用广告,但我不想每次 he/she 访问我的网站时弹出对话框来打扰用户,所以我想给用户一个 "Dont show me again"选项,但我不知道如何实现它。
这是对话框的图片
这是检测广告拦截用户并打开对话框的java脚本代码
<script> window.setTimeout(function(){
if(adsbygoogle instanceof Array) {
// adsbygoogle.js did not execute; probably blocked by an ad blocker
window.location = '#PleaseUnblock'
} else {
// adsbygoogle.js executed
}
}, 2000);
</script>
这是 html 对话框的代码
<div id="PleaseUnblock" class="modalDialog">
<div style="margin-top: 70px;padding: 5px 12px 13px 15px;width: 380px;">
<a href="#" title="Close" class="close">X</a>
<div style="padding: 0; margin: 0;">
<h1 class="ad-di-title">You Are Using AdBlock :(</h1>
</div>
<div style="margin-left: auto;margin-right: auto;width: 350px;height: 332px;background: url(/assets/please.jpg);background-size: 350px;background-repeat: no-repeat"></div>
<p class="ad-di-para" style="margin-bottom: 3px;">All content made on WEBSITENAME is free. As you use Adblock, we wont get any revenue from the content we make. We promise that we will not show annoying ads and we only ask you to enable ads in our site.</p>
<a style="margin-left: 300px" href="#" class="kbtn">Ok</a>
</div>
</div>
使用 cookie 的相当简单的解决方案:
function askLater() {
var d = new Date();
d.setTime(d.getTime() + (86400000)); //set the time to 24 hours later
var expires = "expires="+d.toUTCString();
document.cookie = "dontAsk=true; " + expires;
}
如果用户按下 "Don't ask me again" 按钮,则调用函数 askLater()
。
然后,在您的代码中测试 cookie dontAsk,例如:
if(adsbygoogle instanceof Array && document.cookie.indexOf("dontAsk") == -1) {
// indexOf is -1 when string not found, so the cookie is unset
// adsbygoogle.js did not execute; probably blocked by an ad blocker
window.location = '#PleaseUnblock'
} else { ... }
如果您不想再询问,请改用此方法:
function neverAsk() {
document.cookie="dontAsk=true";
就这么简单。