Alex Rivera | Logout

JavaScript alerts in an onclick in a Chrome extension popup immediately disappear

Asked 2011-05-29T00:08:13.827
10

I'm working on a Chrome extension, and want to use prompt() to get input from the user when they click on certain elements. Unfortunately, for some reason, I can't get prompt() or alert() to work when called as an onclick (or in a jQuery $('#something').click(function), which is how I originally ran into this).

To wit, if I use the HTML below as the popup.html for my extension, the first alert shows up, but the second one flashes on the screen and then immediately disappears without any user intervention. And then the extension popup also immediately closes.

<script>
alert("This alert works");
</script>
<input type="button" onclick="alert('This one disappears')" value="Button"/>

Any thoughts on why this might be happening and how to fix it would be greatly appreciated.

Edit
Report

1 Answer

9

Alerts/prompts are not working inside popups (see this bug report for details). You need to find alternate solution (use html form instead).

answered 2011-05-29T00:15:09.223

Your Answer