Topic: IE error with unload event in Prototype

IE is returning an error when I click cancel on the confirmation
message. You can view the source here:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  <meta http-equiv="content-type" content="text/html; charset=windows-1250">
  <meta name="generator" content="PSPad editor,">
  <title>unload problem</title>
  <script type="text/javascript" src="prototype.js"></script>

    <form id="myform">
      <input id="mytext" name="mytext" value="http://">
      <input id="mybutton" type="button" name="Go" value="Go">
    <a href="">Google</a>

  <script type="text/javascript">
    document.observe('dom:loaded', function() {

      Event.observe('mybutton', 'click', function() {
        window.location.href = $('mytext').value;     

      Event.observe(window, 'beforeunload', function(evt) {
        evt.returnValue = 'Yo foo, leaving already?';



The happy path:
1) fill out a proper url in the text box
2) click go
3) page returns a confirmation message asking if you're sure you want
to leave
4) click cancel, and the page doesn't unload
The error happens in IE after I click cancel. Interestingly, if I
click the Google link I don't get this error.
Any thoughts and suggestions? Thanks so much for your help.

Last edited by JackBauer (2009-02-13 21:07:00)

Re: IE error with unload event in Prototype

I got some help from the Prototype mailing list. It was suggested that I wrap my call to location.href in a try/catch block. That seems to have solved this IE problem.