Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

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


View products that this article applies to.

This article was previously published under Q328807

↑ Back to the top


Symptoms

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

↑ Back to the top


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.

↑ Back to the top


Status

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

↑ Back to the top


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)
%>

↑ Back to the top


Keywords: KB328807, kbbug, kbdhtml

↑ Back to the top

Article Info
Article ID : 328807
Revision : 4
Created on : 11/29/2007
Published on : 11/29/2007
Exists online : False
Views : 345