===============add element=================
function AddControl(objId)
{
var container = document.getElementById(objId);
var fIndex=1;
for(var i=0; i<container.childNodes.length; i++)
{
if(typeof(container.childNodes[i].id)=="string" && container.childNodes[i].id.substring(0,4) == "file")
fIndex++;
}
var newFile = document.createElement("input");
newFile.setAttribute("type","file");
newFile.setAttribute("id","file"+fIndex);
newFile.setAttribute("name","file" + fIndex);
container.appendChild(newFile);
var newBR = document.createElement("br");
container.appendChild(newBR);
}
--window close event---
function DetectBrowserExit()
{
alert('Execute task which do you want before exit');
}
window.onbeforeunload = function(){ DetectBrowserExit(); }