Microsoft KB Archive/328807

= BUG: onbeforeunload May Not Fire When You Move from an XML Page =

Article ID: 328807

Article Last Modified on 11/29/2007

-

APPLIES TO


 * Microsoft Internet Explorer (Programming) 5.5 SP2
 * Microsoft Internet Explorer 6.0
 * Microsoft Internet Explorer 6.0

-



This article was previously published under Q328807





SYMPTOMS
When you move from an XML page in a frameset, the onbeforeunload event does not fire.



RESOLUTION
There are several ways to work around this behavior:


 * Put the XML data in an iframe object, and then move the onbeforeunload event handler to the parent frame.
 * Display the XML data in a new window.
 * Perform the XML/XSL transform on the server-side, and then stream back the HTML frameset that results.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



MORE INFORMATION
Put the following files on a Web server to demonstrate the workaround and the reproduction for each example. After you save all eight individual files, view the Start.htm Web page, and then follow the instructions to start the sample code. Replace Myserverdirectory in Test3.asp with the path that contains the Repro.xml and Repro.xsl files.

Repro.xml

  MyFrame

Repro.xsl

 

  

 <![CDATA[

function MyOnBeforeUnload {   alert(&quot;MyOnBeforeUnload&quot;); } ]]></SCRIPT>

</HEAD> <BODY onbeforeunload=&quot;MyOnBeforeUnload&quot;> My XML/XSL document </BODY> </HTML> </xsl:template> </xsl:stylesheet> Start.htm <FRAMESET ROWS=&quot;10%, *&quot;> <FRAME scrolling=&quot;no&quot; SRC=&quot;about:blank&quot;> <FRAME scrolling=&quot;no&quot; SRC=&quot;startbottom.htm&quot;> </FRAMESET>

Startbottom.htm bottom frame Tests (for each test, click the link and then hit the back button or close the new window). <a href=&quot;Repro.xml&quot; target=&quot;_top&quot;>How it should work</a> <a href=&quot;Repro.xml&quot;>Repro</a> <a href=&quot;Test1.htm&quot;>Workaround 1</a> - Put all XML stuff except onbeforeunload in an iframe <a href=&quot;Repro.xml&quot; target=&quot;newwindow&quot;>Workaround 2</a> - Open a new window <a href=&quot;Test3.asp&quot;>Workaround 3</a> - Use ASP Perform the XML->HTML transform on the server side and stream the HTML file. Test1.htm <HTML> <HEAD> <script language=&quot;jscript&quot;> function MyOnBeforeUnload {   alert(&quot;MyOnBeforeUnload&quot;); } <body leftMargin=0 rightMargin=0 topMargin=0 bottomMargin=0 onbeforeunload=&quot;MyOnBeforeUnload&quot;> <iframe frameBorder=0 width=&quot;100%&quot; height=&quot;100%&quot; scrolling=&quot;no&quot; src=&quot;test1.xml&quot;> </HTML> Test1.xml <?xml version=&quot;1.0&quot;?> <?xml-stylesheet type=&quot;text/xsl&quot; href=&quot;test1.xsl&quot;?> MyFrame Test1.xsl <?xml version=&quot;1.0&quot;?> <xsl:stylesheet xmlns:xsl=&quot;http://www.w3.org/TR/WD-xsl&quot; language=&quot;javascript&quot;> <xsl:template match=&quot;/&quot;> <HTML> <BODY> My alternative XML/XSL document </BODY> </HTML> </xsl:template> </xsl:stylesheet> Test3.asp <%   Response.ContentType = &quot;text/html&quot;

Set xmlDoc = Server.CreateObject(&quot;Microsoft.XMLDOM&quot;) Set xslDoc = Server.Createobject(&quot;Microsoft.XMLDOM&quot;)

xmlDoc.Load(&quot;C:\\Myserverdirectory\\repro.xml&quot;) xslDoc.load(&quot;C:\\Myserverdirectory\\repro.xsl&quot;)

Response.Write xmlDoc.transformNode(xslDoc) %>

Keywords: kbdhtml kbbug KB328807

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.