Search code examples
javascriptalertonbeforeunload

javascript how to use smoke.js with onbeforeunload?


i am using smoke.js to create some neat alerts :)

the problem comes when i try to use it on the onbeforeunload event.

i place it like this:

<body onbeforeunload="javascript:tstconfirm();">

but looks like the script gets unloaded or something because the script doesn't work.

if i try:

<body onbeforeunload="javascript:alert('test');">

the alert works.

any ideas on how to fix this ?

thanks


Solution

  • fixed.

    <script language="JavaScript">
    $(function() {
    $(window).bind('beforeunload', function() {
        setTimeout(function() {
            setTimeout(function() {
               $(".black").css('display', 'block');
             // or do something else
            }, 1000);
        },1);
        return 'Wait! Save up to $20 Today!';
    });
    });
    </script>