@@ -163,23 +163,25 @@ Promo.prototype.post_promo_display = function () {
163
163
}
164
164
} ;
165
165
166
- function detect_adblock ( xhr ) {
167
- if ( xhr && xhr . status === 404 ) {
168
- // Any other status (eg. 500, 502) implies that ads are down
169
- // for a reason other than ad-blocking
170
-
171
- // Check if our ad element is blocked
172
- $ ( '<div />' )
173
- . attr ( 'id' , 'rtd-detection' )
174
- . attr ( 'class' , 'ethical-rtd' )
175
- . html ( ' ' )
176
- . appendTo ( 'body' ) ;
177
- if ( $ ( '#rtd-detection' ) . height ( ) === 0 ) {
178
- return true ;
179
- }
166
+ function detect_adblock ( ) {
167
+ // Status codes are not correctly reported on JSONP requests
168
+ // So we resort to different ways to detect adblockers
169
+ var detected = false ;
170
+
171
+ // Check if our ad element is blocked
172
+ $ ( '<div />' )
173
+ . attr ( 'id' , 'rtd-detection' )
174
+ . attr ( 'class' , 'ethical-rtd' )
175
+ . html ( ' ' )
176
+ . appendTo ( 'body' ) ;
177
+ if ( $ ( '#rtd-detection' ) . height ( ) === 0 ) {
178
+ detected = true ;
180
179
}
181
180
182
- return false ;
181
+ // Remove the test element regardless
182
+ $ ( '#rtd-detection' ) . remove ( ) ;
183
+
184
+ return detected ;
183
185
}
184
186
185
187
function adblock_admonition ( ) {
@@ -275,10 +277,10 @@ function init() {
275
277
promo . display ( ) ;
276
278
}
277
279
} ,
278
- error : function ( xhr , textStatus , errorThrown ) {
280
+ error : function ( ) {
279
281
console . error ( 'Error loading Read the Docs promo' ) ;
280
282
281
- if ( ! rtddata . ad_free && rtd . api_host === 'https://readthedocs.org' && detect_adblock ( xhr ) ) {
283
+ if ( ! rtddata . ad_free && rtd . api_host === 'https://readthedocs.org' && detect_adblock ( ) ) {
282
284
adblock_admonition ( ) ;
283
285
adblock_nag ( ) ;
284
286
}
0 commit comments