Add events via DOM in IE and FF

From MapbenderWiki

Jump to: navigation, search

IE can“t handle the function setAttributes.

You can find this example in the module mod_savewmc in line 44. It saves the current state of Mapbender as a WMC, if the window is closed (onunload)

var node = document.getElementsByTagName('body')[0]; //could be any node

// Internet explorer
if (ie) {
   node.onunload = function() {

      // generate a new function
      // (the first parameter is the argument list (here: empty),
      // the second parameter is the code you want to execute)
      var x = new Function ("", "mod_savewmc_session()"); 

      // execute the new function
      x(); 
   };
}

// Firefox
else {
   node.setAttribute("onunload", "mod_savewmc_session();");
}
Personal tools