help needed to close a window in Javascript

Hi,
I have a requirement where I want to print preview only the HTML table instead of all the details which are present on a screen or web page. So I am fetching only the table data in a new window and then I get print preview pop up. Now what I want is to close the new window after the print preview pop up comes up. The problem here is that the command window.close(); does not close the child/new window. Please help me out in this. I tried window.documnet.close(); also but this is also not working. Here the child window is childWin.and at which place that window should be closed

 This method is claeed on the click of "print preview "button which is on the main screen and table ID is the id of the table to be printed

function fnPrintPreview(tableID)
      {
            var tableData = document.getElementById(tableID).innerHTML;
            childWin = window.open('');
            //writing the content of the table to be printed in a new window
            childWin.document.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"\n',
            '"http://www.w3.org/TR/html4/strict.dtd">\n',
            '<html>\n',
           '<head>\n',
            '<title>Print Preview</title>\n',
            '<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">\n',
            '<LINK href="../css/PrintCSS.css" rel="stylesheet" type="text/css">',
            '</head>',
            '<body>\n',
            ''+tableData+'\n',
            '</body>\n',
           '</html>',
            '<script>',
            //to get the print preview pop up
 
            'var OLECMDID = 7;',
 
            'var PROMPT = 1; ',
            'var WebBrowser = ','\'<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>\'',';',
            'document.body.insertAdjacentHTML(','\'beforeEnd\'',', WebBrowser); ',
            'WebBrowser1.ExecWB(OLECMDID, PROMPT);',
            'WebBrowser1.outerHTML = ""',
            '</script>'
            );
This method is claeed on the click of "print preview "button which is on the main screen and table ID is the id of the table to be printed

Open in new window

varuna123Asked:
Who is Participating?
 
qwerty021600Connect With a Mentor Commented:
< a href="javascript:window.opener='x';window.close();">Close< /a>

another code
<html>
<head>
 <title>JavaScript Window Close Example </title>
</head>
<SCRIPT language="JavaScript1.2">
function popuponclick()
{
 my_window = window.open("",
    "mywindow","status=1,width=350,height=150");
my_window.document.write('<H1>The Popup Window</H1>');  
}

function closepopup()
{
 if(false == my_window.closed)
 {
    my_window.close ();
 }
 else
 {
    alert('Window already closed!');
 }
}
</SCRIPT>
<body>
<P>
<A href="javascript: popuponclick()">Open Popup Window</A>
</P>
<P>
<A href="javascript: closepopup()">Close the Popup Window</A>
</P>
</body>
</html>
0
 
mstrelanConnect With a Mentor Commented:
A real solution would be to create a print stylesheet
<link rel="stylesheet" href="styles/print.css" media="print">

in that stylesheet just make everything you don't want to see display:none and make sure the table is display:block

no javascript required
0
 
CWS (haripriya)Commented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0
All Courses

From novice to tech pro — start learning today.