0
<script src="/assets/js/ads.js" type="text/javascript"></script>
//the bait for adblocker

<script type="text/javascript">

if ((document.getElementById('ElvJCLbfcHDP')) && (window.innerWidth > 1280)){
   window.location = "/disableadblock.php";
}
else {
    do nothing
}
</script>

The ads.js has the element and if the element is blocked then I want the pc user to get redirected to the adblock disable page. If the element is present then do nothing. The requirement is that if a mobile user is blocking the ads then he should not be redirected. Only pc users should be redirected. So it should match two conditions that is check if element is not present and also check if his screen width is more than 1280.

This is my first time doing javacript and I don't know how to do it. I googled a lot but couldn't find anything.

2 Answers 2

1

check if element is not present and also check if his screen width is more than 1280.

According to your requirement, it should be:

if (!document.getElementById('ElvJCLbfcHDP') && (window.innerWidth > 1280)){
   window.location = "/disableadblock.php";
}
Sign up to request clarification or add additional context in comments.

1 Comment

i just tried it without using adblock too.but even if the element is present it gets redirected.what to do?
0

In case the ads is not generated synchronous you have to delay this check

setTimeout(function(){ 
var adsEl = document.getElementById('ElvJCLbfcHDP');
if (!adsEl  && window.innerWidth > 1280){
   window.location = "/disableadblock.php";
}
}, 300);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.