Javascript: Why sometimes alert() does not work but console.log() does?

If you override alert function so it won't work

alert = function() 
{
 ...
};

alert('hello') // won't show any alert

This is a very common problem, and everyone has faced this problem atleast once. The reason alert() does not work is because previously you have checked "prevent this page from creating additional dialoug" checkbox.

lets take a look at this code.

<script type="text/javascript">

var js_name = ['elem1', 'elem2']

 for (var i = 0; i < js_name.length; i++) {
    alert(js_name[i]);
 };

</script>

There will be two alert boxes if you run the code. If you check the "prevent this page from creating additional dialoug" checkbox and then refresh the page again you won't get alert box ever again.

Solution is you need to close that webpage and reopen again in the browser(don't need to close the entire browser). I am assuming you are using chrome. Internet Explorer or FireFox doesn't have this checkbox feature.


To my knowledge alert() is always shown unless it is repetitive in which case you are asked if you want to continue showing alerts.

I suppose the specifics on how this is handled depends on your browser. Care to share any more details? :)


This also happens in ColdFusion. If you use anywhere after the script tag a cflocation tag (instead of location.href) the alert will not show.