Link to home
Start Free TrialLog in
Avatar of varuna123
varuna123

asked on

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

ASKER CERTIFIED SOLUTION
Avatar of qwerty021600
qwerty021600
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.