1. onbeforeunload
This event trigger when the page will unload, the browser will popup a confirm message box to ask whether you want to navigate from this page to another page, it is browser behavior. If we don't want trigger this event(popup confirm message box), we just need close the onbeforeunload event, using the code like: window.onbeforeunload = null.
-eg.
This event trigger when the page will unload, the browser will popup a confirm message box to ask whether you want to navigate from this page to another page, it is browser behavior. If we don't want trigger this event(popup confirm message box), we just need close the onbeforeunload event, using the code like: window.onbeforeunload = null.
-eg.
function fireBeforeUnloadAlert() {
if (documentChanged) {
setTimeout("document.body.style.cursor = 'auto'", 100);
return '';
}
window.onbeforeunload = null;
// just return undefined
}
2.clone object in js
/*
* Function: cloneObject
*
* Description: clone a new object from original object, the clone depth is level 2
*
* level 1 - copy reference
*
* level 2 - copy first level children(the primitives or children object's reference)
*
* Parameter: originalObj - the object will be cloned
*
* Return: a new object equivalent with original object
*/
function cloneObject(originalObj) {
if(typeof(originalObj) != 'object') return originalObj;
if(originalObj == null) return originalObj;
var destinationObj = new Object();
for(var i in originalObj) {
destinationObj[i] = originalObj[i];
/* do complete clone by recursion */
// destinationObj[i] = cloneObject(originalObj[i]);
}
return destinationObj;
}