开发者

How can I control the action of onbeforeunload in IE?

开发者 https://www.devze.com 2022-12-24 19:18 出处:网络
I\'ve got a problem about onbeforeunload recently that I need to pop up a voting page when users try to closetheir IE browsers.I did it by using:

I've got a problem about onbeforeunload recently that I need to pop up a voting page when users try to close their IE browsers.I did it by using:

<body onbeforeunload="makevote()">

And the main structure of makevote() in javascript is 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()');
    }

}

In 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? For example if I click the "OK" ,I'll go to the voting box instead of closing my IE.So far what I can do is only defining the message it shows.And is there any other better way to do this?Help would be greatly appreciated!

Regards


Quite simply, you can't.

This is built-in behaviour, designed to only allow very minimal changes for security purposes. It's the same in every browser; FF, Chrome, etc, all will behave the same way.

The primary purpose for the beforeunload is for things like allowing the users the option to save changes before their changes are lost.

Besides, if your users are leaving, it's already too late - they won't want to answer a survey anymore, they're done!

0

精彩评论

暂无评论...
验证码 换一张
取 消