Driver Scanner 2012 - Free Scan Now
Results 1 to 3 of 3

Thread: Windows 7 problem with submit in onbeforeunload event in IE

  1. #1
    wjmcknight is offline Junior Member Array
    Join Date
    May 2011
    Posts
    4

    Default Windows 7 problem with submit in onbeforeunload event in IE

    This problem only occurs in IE8 on Windows 7. It does not occur in IE8 in any previous version of windows.

    I have a simple page which includes an iFrame control who's source is a second simple page. The second page has an "onbeforeunload" event and some javascript to run for that event. This event simply attempts to do "document.forms[0].submit()". Prior to Windows 7, this code worked. However with Windows 7 the code exceptions on the submit call with an "Access Denied" error.

    I have browsed other similar questions, and what few there are have suggestions of browser security setting. I have lowered the settings in the browser to "low", yet the error still occurs. The two pages in question are below, there is no code behind.

    Default.aspx

    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

    <html>
    <head>
    <title>Testing</title>
    </head>
    <body>
    <form id="Default">
    <iframe src="VarInfo.aspx"></iframe>
    </form>
    </body>
    </html>

    VarInfo.aspx

    <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="VarInfo.aspx.vb" Inherits="WebSite1.VarInfo" %>

    <html>
    <head>
    <title>simple page</title>
    <script language="javascript" type="text/javascript">
    <!--
    function BeforeClose()
    {
    try
    {
    alert('saving');
    document.forms[0].submit();
    alert('saved');
    }
    catch(e)
    {
    alert('Error submitting: ' + e.message);
    }
    }
    //-->
    </script>
    </head>
    <body onbeforeunload="BeforeClose();">
    <form id="VIForm">
    <div>
    VarInfo Page
    </div>
    </form>
    </body>

    </html>

    Would greatly appreciate any help with this one!

  2. Sponsored Links



  3. #2
    wjmcknight is offline Junior Member Array
    Join Date
    May 2011
    Posts
    4

    Default

    Hi All,

    I can now confirm that this is also an issue when running Windows Vista and using IE9.

    Willie John McKnight

  4. #3
    wjmcknight is offline Junior Member Array
    Join Date
    May 2011
    Posts
    4

    Default

    Solution:

    After much trial and error I have the solution. It would seem that in Windows 7 and IE9, a child form is no longer allowed to submit. The trick is to have the parent call the submit for the child form. So the solution is to remove the onbeforeunload event from the child form and place one on the parent. The parent JavaScript must then call the submit.

    VarInfo.aspx

    <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="VarInfo.aspx.vb" Inherits="WebSite1.VarInfo" %>

    <html>
    <head>
    <title>simple page</title>
    </head>
    <body>
    <form id="VIForm">
    <div>
    VarInfo Page
    </div>
    </form>
    </body>

    </html>

    Default.aspx

    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

    <html>
    <head>
    <title>Testing</title>
    <script language="javascript" type="text/javascript">
    <!--
    function BeforeCloseParent()
    {
    try
    {
    alert('saving');
    var frame = window.frames["theIFrame"];
    var form = frame.document.getElementById("VIForm");
    form.submit();
    alert('saved');
    }
    catch(e)
    {
    alert('Error submitting: ' + e.message);
    }
    }
    //-->
    </script>
    </head>
    <body onbeforeunload="BeforeCloseParent();">
    <form id="Default">
    <iframe id="theIFrame" src="VarInfo.aspx"></iframe>
    </form>
    </body>
    </html>

    This works just fine!

Similar Threads

  1. Replies: 5
    Last Post: 25th May 2011, 10:46
  2. Replies: 0
    Last Post: 18th November 2009, 00:21
  3. Replies: 0
    Last Post: 18th November 2009, 00:21
  4. Replies: 0
    Last Post: 18th November 2009, 00:20

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Recommended Download



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47