How can I control the action of onbeforeunload in IE?

Posted by SpawnCxy on Stack Overflow See other posts from Stack Overflow or by SpawnCxy
Published on 2010-03-25T04:00:55Z Indexed on 2010/03/25 4:03 UTC
Read the original article Hit count: 427

Filed under:
|
|

Hi all

I've got a problem about onbeforeunload recently that I need to pop up a voting page if the user try closes their IE browser.And I did it by using

<body onbeforeunload="makevote()">

And the main structure of makevote() in javascript as follows:

function makevote()
{
    comet.distruct();
    if(csid != null && isvote == null)
    {
        window.event.returnValue = false
        window.event.returnValue='press “cancel” to vote please!'
        showComDiv(popvote,"popiframe",400,120,'your vote here','dovote()');
    }

}

For last three months this voting function performed so ugly that I got only less than 8,000 votes from more than 4,50,000 vistors.I think the problem is, when the users try to close their browsers,the onbeforeunload property pops up a comfirm box which covered my voting box while most users click the OK button,which means close comfirming is done,as a habit.So my question is how can I control the comfirming box made by onbeforeunload myself? So far I can only define the message it shows.For example if I click the "OK" ,I'll go to the voting box instead of closing my IE.And if there's any other better way to do this?Help would be greatly appreciated!

Regards

© Stack Overflow or respective owner

Related posts about html

Related posts about JavaScript