'nuff said. I have absolutely no clue why using alert() there wouldn't work. It works perfectly in Firefox, but gives that error in Chrome.
This question is related to
javascript
google-chrome
alert
put this line at the end of the body. May be the DOM is not ready yet at the moment this line is read by compiler.
<script type="text/javascript" src="script.js"></script>"
Here is a snippet that does not need ajQuery and will enable alerts in a disabled iframe (like on codepen)
for (var i = 0; i < document.getElementsByTagName('iframe').length; i++) {
document.getElementsByTagName('iframe')[i].setAttribute('sandbox','allow-modals');
}
Here is a codepen demo working with an alert() after this fix as well: http://codepen.io/nicholasabrams/pen/vNpoBr?editors=001
Take a look at this thread: http://code.google.com/p/chromium/issues/detail?id=4158
The problem is caused by javascript method "window.open(URL, windowName[, windowFeatures])". If the 3rd parameter windowFeatures is specified, then alert box doesn't work in the popup constrained window in Chrome, here is a simplified reduction:
http://go/reductions/4158/test-home-constrained.html
If the 3rd parameter windowFeatures is ignored, then alert box works in the popup in Chrome(the popup is actually opened as a new tab in Chrome), like this:
http://go/reductions/4158/test-home-newtab.html
it doesn't happen in IE7, Firefox3 or Safari3, it's a chrome specific issue.
See also attachments for simplified reductions
I had the same issue recently on my test server. After searching for reasons this might be happening and testing the solutions I found here, I recalled that I had clicked the "Stop this page from creating pop-ups" option a few hours before when the script I was working on was wildly popping up alerts.
The solution was as simple as closing the tab and opening a fresh one!
Source: Stackoverflow.com