onbeforeunload-close_with_javascript.html   [plain text]

<html lang="en">
<script language="JavaScript">
function openWindow() {
<BODY onbeforeunload="return 'onBeforeUnloadHandler return string is displayed here.';">
<p><b>BUG ID:</b> <a href="rdar://problem/4394910">4394910</a> calling Javascript window.close() does not trigger onbeforeunload event</p>

<p id="test" style="background-color:skyblue; padding:3px;"><b>STEPS TO TEST:</b> 
	<li>Click the "Open" button below.  
	<li>In the window that opens, click the "Close" button.

<p id="success" style="background-color:palegreen; padding:3px;"><b>TEST PASS:</b> 
After the close button is clicked, you should see a dialog that reads:</p>
<pre>Are you sure you want to navigate away from this page?

onBeforeUnloadHandler return string is displayed here.

Press OK to continue or Cancel to stay on the current page.</pre>
<p id="success" style="background-color:palegreen; padding:3px;">You should see the same dialog if you click the "Close" button in the main window.

<p id="failure" style="background-color:#FF3300; padding:3px;"><b>TEST FAIL:</b>  
No dialog (as described above) after clicking the "Close" button in the newly opened window, or in the main window.

<BODY onbeforeunload="return 'onBeforeUnloadHandler return string is displayed here.';">
<input type=button value="Open Window" onclick="openWindow()"><br>
<input type=button value="Close Window" onclick="window.close();"><br>
<p>Click the Open Window button.  Once the new window is opened, close the new window by clicking the Close Window button (not the browser's close window icon).</p>