Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 503
yuji Avatar asked May 29 '11 00:05

yuji


1 Answers

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

like image 140
serg Avatar answered Oct 16 '22 06:10

serg