问题描述
我正在研究Chrome扩展程序,并希望在用户点击某些元素时使用prompt()来获取用户的输入。不幸的是,出于某种原因,当我作为一个onclick(或者在一个jQuery $('#something')。click(function))中调用时,我无法使prompt()或alert()工作,这就是我最初遇到的如果我使用下面的HTML作为我的扩展程序的popup.html,第一个警报出现,但第二个警报在屏幕上闪烁然后立即消失而没有任何用户干预。然后扩展弹出窗口也会立即关闭。
< script>
alert(此警报有效);
< / script>
< input type =buttononclick =alert('This one disappear')value =Button/>
想知道为什么会发生这种情况以及如何解决这个问题,我们将不胜感激。
警报/提示不适用于弹出窗口(请参阅以获取详细信息)。你需要找到替代解决方案(改用html表单)。
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.
Alerts/prompts are not working inside popups (see this bug report for details). You need to find alternate solution (use html form instead).
这篇关于Chrome扩展程序弹出窗口中的onclick中的JavaScript警报立即消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!