help needed to close a window in Javascript

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 ='');
            //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',
            '<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">',
            //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 = ""',
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

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

another code
 <title>JavaScript Window Close Example </title>
<SCRIPT language="JavaScript1.2">
function popuponclick()
 my_window ="",
my_window.document.write('<H1>The Popup Window</H1>');  

function closepopup()
 if(false == my_window.closed)
    my_window.close ();
    alert('Window already closed!');
<A href="javascript: popuponclick()">Open Popup Window</A>
<A href="javascript: closepopup()">Close the Popup Window</A>
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
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.
All Courses

From novice to tech pro — start learning today.