23

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.

0

3 Answers 3

22

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.

5
  • 7
    I accepted this answer so hard my mouse exploded. Works like a charm. Thank you very much ^^
    – CreeDorofl
    Commented Jul 31, 2012 at 17:16
  • You're welcome! Glad to help. Commented Jul 31, 2012 at 18:12
  • Why is not recommended to disable all alerts? I never came accross useful alerts except "do you really want to exit this tab" on unsaved progress pages.
    – Arian
    Commented Apr 5, 2017 at 18:31
  • Doesn't work if the page shows alerts during load.
    – riv
    Commented Sep 24, 2018 at 18:33
  • @riv, open a new question if you have a case where it doesn't work. Be sure to provide a complete recipe for duplicating the problem. Commented Sep 24, 2018 at 19:02
3

There is at least one extension for that in the Chrome Web Store. Works for me, even though it sounds a bit suspect that it has an optional support by ads mode you can disable in its settings page. (I didn't find the setting, but figured it couldn't hurt null routing api.s13.us.)

0

If you are looking for a tool for this and don't want to mess with user scripts - there is nice tool that can handle any annoying popup on a Windows system - ClickOff. You can download it from here. I checked, it works with "Changes you made may not be saved" alert for SharePoint sites.

2
  • this sounds interesting, as annoying error popups would be nice to remove in general. Does it let you specify exactly what sort of dialogues you want to automatically OK/cancel, or does it somehow choose them by itself?
    – CreeDorofl
    Commented Mar 31, 2017 at 19:19
  • Yes, you can specify what dialogues to close and the button to click.
    – Serhiy
    Commented Apr 3, 2017 at 4:57

You must log in to answer this question.

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