How can I disable javascript popups/alerts in Chrome?

19
2014-04
  • CreeDorofl

    Sorry if it's been asked. I've already found several solutions that aren't working. Not sure what I'm doing wrong.

    I don't want to disable all javascript, only Javascript alert boxes. The ones that pop up and force you to click OK or X to close them.

    I've found user scripts that claim to do this (example: http://userscripts.org/scripts/show/58252 ). I've put chrome on the dev channel, start chrome with the --enable-user-scripts switch, the script shows up as installed.

    But I still get the alert boxes.

    An example alert box that isn't getting disabled is at http://wordswithfriends.net/ - put in any garbage word into the word validator on the right sidebar. You get a popup telling you it's not a word.

  • Answers
  • Brock Adams

    The only way to disable the alert boxes is to install either an extension or a userscript. The userscript you linked is for Firefox Greasemonkey and will not work on Chrome.

    Additionally, the misbehaving page you cite is sneaky and runs that "word validator" in an iframe with code that fires the alert() immediately upon iframe reload.

    But here's a userscript that defeats it:

    // ==UserScript==
    // @name        Wordswithfriends, Block javascript alerts
    // @match       http://wordswithfriends.net/*
    // @run-at      document-start
    // ==/UserScript==
    
    addJS_Node (null, null, overrideSelectNativeJS_Functions);
    
    function overrideSelectNativeJS_Functions () {
        window.alert = function alert (message) {
            console.log (message);
        }
    }
    
    function addJS_Node (text, s_URL, funcToRun) {
        var D                                   = document;
        var scriptNode                          = D.createElement ('script');
        scriptNode.type                         = "text/javascript";
        if (text)       scriptNode.textContent  = text;
        if (s_URL)      scriptNode.src          = s_URL;
        if (funcToRun)  scriptNode.textContent  = '(' + funcToRun.toString() + ')()';
    
        var targ = D.getElementsByTagName ('head')[0] || D.body || D.documentElement;
        targ.appendChild (scriptNode);
    }
    

    If you really want to disable ALL alerts() on ALL pages (Not recommended), then delete the // @match line.

  • sandhus

    These popups are ads. Just install adblock plus extension for chrome.


  • Related Question

    How do I disable Javascript in Chrome?
  • Jude Allred

    How do I disable Javascript in Chrome?


  • Related Answers
  • Pacerier

    Go the address bar and type chrome://settings/content (Wrench >> Settings >> Search "javascript")

    You can disable javascript by selecting "Do not allow any site to run JavaScript".

    http://screenshoot.me/sfgLrl

  • goodeye

    Another way:

    Quick Javascript Switcher, a Chrome extension for quickly enabling / disabling Javascript) :

  • Perry

    via http://www.google.com/support/forum/p/Chrome/thread?tid=5e291648113cc731&hl=en:

    To disable JS on Windows, find your Google Chrome shortcut (say, on your desktop or somewhere similar). Right-click it, and go to Properties. In the "Target:" field, put "-disable-javascript" after the quotation marks.

    Any better ways?

  • Joshua

    Yet another way to do this that might be easier:

    Pull up the Chrome Console, and click on the settings icon in the lower-right. At the top in "General" is the option to disable Javascript - along with lots of other easier-to-access goodies.

  • Michael Hampton

    I'm still using NotScripts, because it blocks more than just JavaScript, allows for both temporary and permanent exceptions, and it actually has a decent UI (unlike Chrome's built-in functionality).

  • Indrek

    You can use the Quick Javascript Switcher extension.