Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

On an active website I go to, there is this javascript code that is displayed on every page.

<script type="text/javascript">
(function(){var d=document;var i=d.getElementsByTagName('iframe');if(google_ad_client!=null||(window.getComputedStyle?d.defaultView.getComputedStyle(i[i.length-1],null).getPropertyValue('display'):i[i.length-1].currentStyle['display'])=='none'){

alert('Adblock detected, please consider disabling it')


Is there any way that I could get my adblock -- or any other type of plugin -- to disable that specific code without disabling all javascript?

share|improve this question
On a side note, I had disabled my adblock entirely. The script continues to display the alert. Maybe it's in the cause of my OS being a Linux Distribution.. – D-Vee Oct 26 '13 at 13:58
Regardless of your comment, these links may be helpful: 1, 2. Basically, there is no easy way to disable an inline script (which is in the HTML), but you can block an external script. If the code you posted is an external script, it's a duplicate of this question: – amiregelz Oct 26 '13 at 14:05
You may be able to override the alert using a userscript (depending on when each piece is loaded in the DOM). Something as simple as alert = function() {}; may work. – nerdwaller Oct 26 '13 at 14:13
@nerdwaller Would it be possible to use something like Stylish to edit the HTML page so that the script does nothing? Secondly, how would I write that as a userscript? I have little to none experience with javascript, but I am able to read it. – D-Vee Oct 26 '13 at 14:14
After a little more research, Userscripts are run after everything else, so that solution doesn't work. I'm not familiar with Stylish enough to give you anything good on that, sorry! – nerdwaller Oct 26 '13 at 14:17

You can use the Greasemonkey add-on to rewrite the alert function:

// ==UserScript==
// @name        Catch JS Alert
// @namespace
// @include     http://*
// @version     1
// @grant       none
// @run-at      document-start
// ==/UserScript==

window.alert = function(message) {
    if(message == 'Adblock detected, please consider disabling it') {
    } else {

The way this works is as follows:

If the alert box's message matches "Adblock detected, please consider disabling it", then discard it to the JS console (it will not be displayed). Otherwise, display the alert box as a confirm box.

share|improve this answer
Why not just keep a reference to the original alert? – Ryan O'Hara Oct 26 '13 at 17:33
Interesting, did not know of the @run-at option. Great intel, +1. – nerdwaller Oct 26 '13 at 17:52
Sorry, but that does not seem to work. o_O – D-Vee Oct 26 '13 at 22:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .