最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Show alert on button click - Stack Overflow

programmeradmin1浏览0评论

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
Add a ment  | 

2 Answers 2

Reset to default 2

Alternatively, 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." );
});
发布评论

评论列表(0)

  1. 暂无评论