onbeforeunload and eval Problems in IE

Last post 04-14-2005 11:39 AM by Scott Mitchell. 2 replies.

Sort Posts:

  • onbeforeunload and eval Problems in IE

    04-12-2005, 4:40 PM
    • Contributor
      4,100 point Contributor
    • Scott Mitchell
    • Member since 06-15-2002, 4:41 PM
    • San Diego, CA
    • Posts 707
    • ASPInsiders
      TrustedFriends-MVPs

    I am using the onbeforeunload client-side event to prompt a user when leaving a page after they have made changes, as discussed in this article of mine: Using ASP.NET to Prompt a User to Save When Leaving a Page.  The problem I am having is with the page unloading via eval.  Specifically, I am using telerik r.a.d. menu, which redirects users to another page via script like:

    eval('window.location.href='url of menu item');

    When a user attempts to leave the page via a menu option, they get the prompt, as expected, but if they click Cancel there is a script error: Unspecified error on the line number of the eval() function call.  This works just fine in Firefox.

    I created a VERY simple page to test this out and confirm that it is the eval() function.  The page below, when visited through IE, displays the prompt and if I click Cancel I get the same Unspecified error. Sad [:(]

    <script>
      function foo()
      {
        return "bar";
      }
     
      window.onbeforeunload = foo;

      eval('window.location.href=\'http://www.google.com\'');
    </script>

    I was unable to find any info via Google as to if this is a well-known bug or if there are any workarounds.  Any ideas/suggestions/comments most appreciated.  (I'm posting this in the telerik forums as well; hopefully there's an easy way to get rid of those eval() statements, but I doubt it... Tongue Tied [:S])

    TIA

    Happy Programming!


    -- Scott Mitchell
    -- mitchell@4guysfromrolla.com
    -- http://scottonwriting.net/sowblog/
    -- http://www.4GuysFromRolla.com/ScottMitchell.shtml
  • Re: onbeforeunload and eval Problems in IE

    04-13-2005, 5:03 PM
    • Contributor
      2,037 point Contributor
    • BasicDatePicker
    • Member since 10-22-2004, 1:32 PM
    • Edmonton, Alberta, Canada
    • Posts 406

    Hi Scott,

    We tried to come up with a solution, although nothing worked. dang.

    We did find that removing the eval() still produced the error. We're going to sleep on this and see what happens. If you come up with a solution or any other notes/comments, please post a follow-up.

    Thanks,
    Geoffrey McGill - Product Manager
    Basic Date Picker - A Quicker Picker(TM) - ASP.NET Calendar, Date and Time Web Controls
  • Re: onbeforeunload and eval Problems in IE

    04-14-2005, 11:39 AM
    • Contributor
      4,100 point Contributor
    • Scott Mitchell
    • Member since 06-15-2002, 4:41 PM
    • San Diego, CA
    • Posts 707
    • ASPInsiders
      TrustedFriends-MVPs
    For those who are interested, the workaround provided by Telerik  was to put the eval() function in a try...catch block, which would have the effect of suppressing the error message shown in IE.  It does serve as a workaround, although seems like a bit of a hack.  Stupid IE. Stick out tongue [:P]
    Happy Programming!


    -- Scott Mitchell
    -- mitchell@4guysfromrolla.com
    -- http://scottonwriting.net/sowblog/
    -- http://www.4GuysFromRolla.com/ScottMitchell.shtml
Page 1 of 1 (3 items)