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.
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.
Share Improve this question asked May 29, 2011 at 0:08 yujiyuji 16.7k4 gold badges64 silver badges64 bronze badges 2- are you sure this is all the code you have on your page? do u have anything overriding alert()? – Ibu Commented May 29, 2011 at 0:12
- My actual extension is a lot longer, but for the purposes of figuring out what the problem was I was whittling down the example to the shortest snippest that would still have the bug. – yuji Commented May 29, 2011 at 8:20
1 Answer
Reset to default 9Alerts/prompts are not working inside popups (see this bug report for details). You need to find alternate solution (use html form instead).