Hi
i am working on a chat module in Yii and implemented the window close prompter function as follows
[code=javascript]
$(document).rea dy(function(){
// Initialise window close prompter
addEvent(window , \'load\', addListeners, true);
});
/*WINDOW CLOSE PROMPTER CODE*/
// Cross browser event handling for IE 5+, NS6+ and Gecko
function addEvent(elm, evType, fn, useCapture)
{
if (elm.addEventLi stener)
{
// Gecko
elm.addEventLis tener(evType, fn, useCapture);
return true;
}
else if (elm.attachEven t)
{
// Internet Explorer
var r = elm.attachEvent (\'on\' + evType, fn);
return r;
}
else
{
// netscape?
elm[\'on\' + evType] = fn;
}
}
// Add Listeners
function addListeners(e)
{
// Before unload listener
addEvent(window , \'beforeunload\ ', exitAlert, false);
}
// Exit Alert
function exitAlert(e)
{
// default warning message
var msg = "You will lose information if it has not already been saved.";
// set event
if (!e) { e = window.event; }
if (e) { e.returnValue = msg; }
// return warning message
return msg;
}
[/code]
now the basic purpose was to prompt the user if he accidentally clicks the close window / TAB button but it prompts me every time when i have to redirect the page for example , if i click endChatSession button it should logout and redirect to the review meeting form but when ever it wil redirect or reload it will call the same prompt, i thought if i could be able to remove / unbind the listener i would be able to achieve what i am trying to do, so i added the following line in the endChatSession function but it is not unbind / removing the listener.
[code=javascript]
window.removeEv entListener('on load',addListen ers,true);
[/code]
any help will be appreciated
regards,
Omer Aslam
i am working on a chat module in Yii and implemented the window close prompter function as follows
[code=javascript]
$(document).rea dy(function(){
// Initialise window close prompter
addEvent(window , \'load\', addListeners, true);
});
/*WINDOW CLOSE PROMPTER CODE*/
// Cross browser event handling for IE 5+, NS6+ and Gecko
function addEvent(elm, evType, fn, useCapture)
{
if (elm.addEventLi stener)
{
// Gecko
elm.addEventLis tener(evType, fn, useCapture);
return true;
}
else if (elm.attachEven t)
{
// Internet Explorer
var r = elm.attachEvent (\'on\' + evType, fn);
return r;
}
else
{
// netscape?
elm[\'on\' + evType] = fn;
}
}
// Add Listeners
function addListeners(e)
{
// Before unload listener
addEvent(window , \'beforeunload\ ', exitAlert, false);
}
// Exit Alert
function exitAlert(e)
{
// default warning message
var msg = "You will lose information if it has not already been saved.";
// set event
if (!e) { e = window.event; }
if (e) { e.returnValue = msg; }
// return warning message
return msg;
}
[/code]
now the basic purpose was to prompt the user if he accidentally clicks the close window / TAB button but it prompts me every time when i have to redirect the page for example , if i click endChatSession button it should logout and redirect to the review meeting form but when ever it wil redirect or reload it will call the same prompt, i thought if i could be able to remove / unbind the listener i would be able to achieve what i am trying to do, so i added the following line in the endChatSession function but it is not unbind / removing the listener.
[code=javascript]
window.removeEv entListener('on load',addListen ers,true);
[/code]
any help will be appreciated
regards,
Omer Aslam
Comment