Was just having a problem getting the IE7 onbeforeunload event to be canceled. Found this blog about it: OnBeforeUnload, IE7, Assigning event handlers to null and the problems that arise.

Pretty simple, just wrap the return with a boolean:

JAVASCRIPT:
  1. var goodExit = false;
  2. window.onbeforeunload = confirmExit;
  3. function confirmExit()
  4. {
  5.   // normally this if-check wouldn't be here,
  6.   // cause the event handler was nulled elsewhere.
  7.   // But IE7 doesn't respect the null, and
  8.   // wants the handler to not return anything
  9.   // (not even null).
  10.   if (!goodExit)
  11.   {
  12.     return "Leaving this page will cause all unplaced orders to be discarded."+
  13.     "  Are you sure you want to leave the page?";
  14.   }
  15.   // notice no return statement here!
  16. }
  17. </script>
  18.  
  19.     . . . . .
  20.  
  21. <input type="image" src="<%=AppService.BASEDIR%>/images/lgrequest.gif" onclick="javascript: goodExit = true; window.onbeforeunload = null; document.forms[0].submit();" />

This example was stolen from Brandon Himes and his blog, The Busted Mug. Thank you Brandon!