2

I posted this question at the end of the workday as my brain was melted.Please help me.
I have a web page, calling a JavaScript Function from an Event Handler. The JavaScript Function is used to close window.
Like this:

<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
function closeWin() {
    window.opener = null;
    window.close();
}
</SCRIPT>
</HEAD>
<BODY>
<FORM>
    <INPUT TYPE="button" VALUE="Close Me" 
    onClick="closeWin()">
</FORM>
</BODY>
</HTML>


This web page is needed to run in Internet Explorer(I use IE7).
When I clicked "Close Me" button,the window would be closed.
My Problem is -
(1)Right-Click on the page and select Print Preview...(Print Preview Page will be shown)
(2)Close the Print Preview Page by clicking on the CLOSE(x) button
(3)And Then click "Close Me" button,the window will not be closed.
So,I don't know how to solve this problem so that the web page close properly by "Close Me" button after viewing Print Preview??

In step (2) -
(2)Close the Print Preview Page by the escape key on keyboard ( Esc )
(3)And Then click "Close Me" button,the window will be closed properly.

I am a beginner at JavaScript and I don't know much about how this problem occurred.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
NNNN
  • 165
  • 2
  • 13
  • I surf the web and found that,the javascript function window.close() will not work after viewing print preview window.This is a bug of Internet Explorer 7~9. – NNNN May 08 '12 at 04:07

2 Answers2

1

this will open the preview window and print dialoge

<script type="text/javascript"><!–
function ClickHereToPrint(){
try{
var oIframe = document.getElementById('ifrmPrint');
var oContent = document.getElementById('divToPrint').innerHTML;
var oDoc = (oIframe.contentWindow || oIframe.contentDocument);
if (oDoc.document) oDoc = oDoc.document;
oDoc.write("<head><title>title</title>");
oDoc.write("</head><body onload='this.focus(); this.print();'>");
oDoc.write(oContent + "</body>");
oDoc.close();
}
catch(e){
self.print();
}
}
// –></script>
Sambath Kumar
  • 153
  • 1
  • 2
  • 10
1

This is a known bug in IE 7, 8 and 9. See this

Subir Kumar Sao
  • 8,171
  • 3
  • 26
  • 47
caradhras
  • 11
  • 1