BUG: onbeforeunload May Not Fire When You Move from an XML Page (328807)



The information in this article applies to:

  • Microsoft Internet Explorer (Programming) 5.5 SP2
  • Microsoft Internet Explorer (Programming) version 6.0
  • Microsoft Internet Explorer (Programming) 6 (SP1)

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
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="repro.xsl"?>
<root>
<name>MyFrame</name>
</root>

Repro.xsl
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl" language="javascript">

<xsl:template match="/">
<HTML>
<HEAD>

<SCRIPT LANGUAGE="JScript">
<xsl:comment><![CDATA[

function MyOnBeforeUnload()
{
	alert("MyOnBeforeUnload");
}
]]></xsl:comment></SCRIPT>

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

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

   Set xmlDoc = Server.CreateObject("Microsoft.XMLDOM")
   Set xslDoc = Server.Createobject("Microsoft.XMLDOM")

   xmlDoc.Load("C:\\Myserverdirectory\\repro.xml")
   xslDoc.load("C:\\Myserverdirectory\\repro.xsl")

   Response.Write xmlDoc.transformNode(xslDoc)
%>


Modification Type:MajorLast Reviewed:5/12/2003
Keywords:kbDHTML kbbug KB328807