admin 管理员组文章数量: 1086019
I'm sure this will turn out to be very simple, I got a piece of code that doesn't seem to be loading properly. This is the code I have on my Simple php page
<script language="JavaScript" type="text/javascript">
function exit_alert(){
alert("Go Install the XX Antivirus now\n\nto prevent more issues!");
}
</script>
The user clicks the only button on the page, as soon as he does it, an exit alert should pop with a message like "Go Install the XX Antivirus now to prevent more issues". The exit alert should be a message only, and should only have an OK button on the bottom, and not ask the user Stay or leave.
I've tried lot of stuff but nothing seems to be working, I could really use your help :)
Big thanks in Advance!
I'm sure this will turn out to be very simple, I got a piece of code that doesn't seem to be loading properly. This is the code I have on my Simple php page
<script language="JavaScript" type="text/javascript">
function exit_alert(){
alert("Go Install the XX Antivirus now\n\nto prevent more issues!");
}
</script>
The user clicks the only button on the page, as soon as he does it, an exit alert should pop with a message like "Go Install the XX Antivirus now to prevent more issues". The exit alert should be a message only, and should only have an OK button on the bottom, and not ask the user Stay or leave.
I've tried lot of stuff but nothing seems to be working, I could really use your help :)
Big thanks in Advance!
Share Improve this question edited Aug 9, 2014 at 2:34 Dave Chen 11k8 gold badges41 silver badges71 bronze badges asked Aug 9, 2014 at 2:16 Mike WhiteMike White 111 gold badge1 silver badge1 bronze badge 3- So, what does happen when you hook a button to that function? – Bob Brown Commented Aug 9, 2014 at 2:28
- 1 The stay or leave buttons are proprietary to the browser, meaning that you can't change it because it depends on which browser the client is using. Are you trying to prevent the user from leaving the page? That's pretty annoying for any website. – Dave Chen Commented Aug 9, 2014 at 2:31
- That's interesting, I gotta do more research on it. I don't care if it's annoying, it means extra 30% return on investment. – Mike White Commented Aug 9, 2014 at 12:53
2 Answers
Reset to default 2Alternatively, you can opt to not load an entire Javascript library for something as simple as this:
document.querySelector('#button').addEventListener('onclick', exit_alert);
You can do this with jQuery
$( "#targetId" ).click(function() {
alert( "Handler for .click() called." );
});
本文标签: javascriptShow alert on button clickStack Overflow
版权声明:本文标题:javascript - Show alert on button click - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744055693a2525803.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论