Hhis code was copied from the top of the email accounts offered by Yola. It shows what can go wrong with bad scripting.
tag of the source document
(IE5 sucks!)
*/
if (typeof doc == 'undefined') {
doc = windowObj.parent.document;
}
return doc;
}
catch(err)
{
return window.document;
}
}
var changeflag = false;
try
{
if ( window.parent && window.parent.changeflag ){
window.parent.changeflag = false;
}
}
catch(err)
{
//there's a problem with the parent
}
var wtype = 't';
// reset any state on the parent window
if ( wtype.toLowerCase() == "a" ){
if ( window.parent.subCanvasSettings ){
window.parent.subCanvasSettings.isModified = false;
}
}
// Cross-browser implementation of element.addEventListener()
function addListener(element, type, expression, bubbling)
{
bubbling = bubbling || false;
if (window.addEventListener) { // Standard
element.addEventListener(type, expression, bubbling);
return true;
} else if (window.attachEvent) { // IE
element.attachEvent('on' + type, expression);
return true;
} else return false;
}
function removeListener(element, type, expression, bubbling){
bubbling = bubbling || false;
if (window.removeEventListener) { // Standard
element.removeEventListener(type, expression, bubbling);
return true;
} else if (window.detachEvent) { // IE
var r = element.detachEvent('on' + type, expression);
return r;
} else return false;
}
//This send a confirmation message to the user and desable the pressed link
function confirmExit(e) {
//Get the clicket element
var tg = (window.event) ? e.srcElement : e.target;
if ( ! tg ){
tg = ( e.target ) ? e.target : e.srcElement;
}
tg = tg.nodeName == 'A'?tg:tg.parentNode;
//If it is an A element
if (tg.nodeName == 'A') {
if (window.changeflag)
{
var answer = confirm('You have some unsaved settings, do you want to continue?');
if(answer)
{
if (typeof tg.hrefOld != 'undefined')
{
tg.href = tg.hrefOld;
}
// reset changeflag
changeflag = false;
if ( wtype.toLowerCase() != "a" ){
var doc = getDocumentObject( window.parent );
removeListener(doc, 'click', confirmExit);
window.parent.changeflag = false;
}
}
else
{
if (typeof tg.hrefOld == 'undefined')
{
tg.hrefOld = tg.href;
tg.href = "#";
}
}
}
else
{
if (typeof tg.hrefOld != 'undefined') {
tg.href = tg.hrefOld;
}
}
}
}
function unsavedChange(evt)
{
//Set true the changeflag
changeflag = true;
addListener(document, 'click', confirmExit);
/**
* If we're in an Ajax-based environment, we simply set the isModified flag
* on the subCanvasSettings.
*/
if ( wtype.toLowerCase() == "a" ){
if ( window.parent.subCanvasSettings ){
window.parent.subCanvasSettings.isModified = true;
}
/**
* When in degraded/basic mode, we set the changeflag on the parent window
* and add a listener in order to display the "unsaved settings" alert when
* the user attempts to leave the settings page without saving any changes.
*/
} else {
window.parent.changeflag = true;
var doc = getDocumentObject( window );
addListener(doc, 'click', confirmExit);
}
}
//Set the title of the document
var doc = getDocumentObject( window );
doc.title = "Webmail";