JavaScript Javascript alert: block if message contains certain word? javascript alert block execution,javascript alert block,javascript block alert

I have a webapp that makes calls to a database. Every once in a while, we get a javascript alert dialog that says that the transaction was deadlocked. Honestly, we don't care if that happens because it's not an interactive app...it just displays data based on a timer and if it misses it this time, it's okay to display it next time around.

I know you can over write the alert method like so:

window.alert = function alert(msg) {
  console.log('Hidden Alert ' + msg);
};

(found at Can I prevent an alert() with a Google Chrome Extension)

The question I have is: Is there a way to see if the message for the alert .containsa specific word or phrase, ignore the alert call if it does but display the alert otherwise? Installing an extension to deal with this really isn't an option.

Clarification:

I know how to catch it if it does or doesn't but what code would I write to go ahead and display the alert like normal if I'm over writing the alert code?

Answer:1
window.default = window.alert;
window.alert = function alert(msg) {
  var word = 'foo';
    if (msg.indexOf(word) != -1){
        console.log('contains');
        // do what you wanna do if contains
    }else{
       window.default(msg);
    }
};

alert('foo');
alert('bar');

http://jsfiddle.net/pnkcpvLj/

Here is my approach.

Answer:2

I'm trying to use formdata object to send form data to my server. I need this because one of my input fields is a file. However the formdata object is blank when I try to send the data to my server, ...

I'm trying to use formdata object to send form data to my server. I need this because one of my input fields is a file. However the formdata object is blank when I try to send the data to my server, ...

  1. formdata object empty
  2. form data empty object
  3. javascript formdata object empty
  4. formdata append empty object
  5. formdata returns empty object

I have a form, which allows to select an item from a dropdown list and upload a file. The name and the ID of the item are saved in a Spreadsheet document. Works with one file...but I want to upload ...

I have a form, which allows to select an item from a dropdown list and upload a file. The name and the ID of the item are saved in a Spreadsheet document. Works with one file...but I want to upload ...

  1. handling multiple files in python
  2. handling multiple files in vi
  3. handling multiple files in c
  4. handling multiple files in vi editor
  5. handling multiple files using awk
  6. vim handling multiple files
  7. handling multiple feature files in cucumber
  8. sftp handling multiple files simultaneously

I am following a tutorial [here][1] to make a Facebook like friend tagging system. But the tutorial lacks the "arrow navigating" capability like Facebook. I would like to figure out how to achieve ...

I am following a tutorial [here][1] to make a Facebook like friend tagging system. But the tutorial lacks the "arrow navigating" capability like Facebook. I would like to figure out how to achieve ...

  1. enable arrow navigation in excel
  2. how to enable arrow navigation

I am using Trisquel 7.0. I've some basic knowledge about html and JavaScript. Now I want to save html form data to file (Also interested in loading/filling html form from file). I searched and found ...

I am using Trisquel 7.0. I've some basic knowledge about html and JavaScript. Now I want to save html form data to file (Also interested in loading/filling html form from file). I searched and found ...

  1. saving html form data to text file
  2. saving html form data to xml
  3. saving html form data
  4. saving html form data to xml using javascript
  5. saving html form data to file
  6. saving html form data to xml using php
  7. html saving form values
  8. html form using php