简体   繁体   English

Chrome 扩展弹出窗口中 onclick 中的 JavaScript 警报立即消失

[英]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.我正在开发 Chrome 扩展程序,并希望在用户单击某些元素时使用 prompt() 来获取用户的输入。 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).不幸的是,由于某种原因,当被称为 onclick(或 jQuery $('#something').click(function) 时,我无法让 prompt() 或 alert() 工作,这就是我最初遇到的方式这个)。

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.也就是说,如果我使用下面的 HTML 作为弹出窗口。html 用于我的扩展,第一个警报会出现,但第二个警报会在屏幕上闪烁,然后在没有任何用户干预的情况下立即消失。 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).您需要找到替代解决方案(改用 html 表格)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM