Important Note
If it was not obvious, the initial inline <script>
in each example needs to be swapped with <script src="/ads/ads.js"></script>
for proper functionality. Unfortunately, I am unable to make that change at this time.
Summary
On your website, the ads.js
file is loaded asynchronously using data-rocketsrc="ads.js"
. To ensure it loads synchronously before the next inline script runs, replace it with src="ads.js"
. Your page should appear as follows (excluding CloudFlare
):
<html>
<head>
<title>Test Adblock</title>
<script src="ads.js"></script>
</head>
<body>
<script>
'use strict';
if (typeof canRunAds === 'undefined') {
document.write('canRunAds is being blocked<br/>');
}
</script>
</body>
</html>
The content of
https://flamingocams.com/ads/ads.js
should simply be:
var canRunAds = true;
Currently, it contains:
<script>var canRunAds=true;</script>
I must confess, my expertise in rocketscript is limited, but I suspect the running context might not be window
. Run it as regular JavaScript to ensure synchronous execution in the window
context.
Solution
Just utilize typeof canRunAds === 'undefined'
. Using window.canRunAds
is unnecessary, as typeof
handles any possible ReferenceError
when checking an undeclared variable, even in strict mode
:
<script>
'use strict';
var canRunAds = true;
// demonstrating the conditional `if`
// var someOtherFlag = true;
</script>
<script>
'use strict';
if (typeof canRunAds === 'undefined') {
document.write('canRunAds is being blocked<br/>');
}
if (typeof someOtherFlag === 'undefined') {
document.write('someOtherFlag is being blocked<br/>');
}
</script>
Typically, having a conditionally visible element based on CSS is more common practice:
p.adblock-warning {
display: none;
color: red;
}
body.adblock p.adblock-warning {
display: initial;
}
<script>
// assuming this couldn't run
// var canRunAds = true;
</script>
<script>
if (typeof canRunAds === 'undefined') {
document.body.classList.add('adblock');
}
</script>
<p class="adblock-warning">Adblock is enabled, Please disabled to continue.</p>