By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,939 Members | 1,602 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,939 IT Pros & Developers. It's quick & easy.

how to hide unwant objects to print?

P: 51
I try to hide the print preview button that inside <div id="button"> when previewing the page. But the the problem happened the button is always hidden after i closing the preview page. Anyone have an idea how to overcome this? Here is the code;

[HTML]<html>
<head>
<script language="javascript">
function printpreview()
{
var OLECMDID = 7;
/* OLECMDID values:
* 6 - print
* 7 - print preview
* 8 - page setup (for printing)
* 1 - open window
* 4 - Save As
* 10 - properties
*/
var PROMPT = 1; // 2 DONTPROMPTUSER
var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
document.getElementById('form').style.display='blo ck';
document.getElementById('button').style.display='n one';
WebBrowser1.ExecWB(OLECMDID, PROMPT);
WebBrowser1.outerHTML = "";
}
</script>
<title>Print Preview</title>
</head>

<body>
<div id="form">
<table id="schedule" width="200" cellpadding="1" cellspacing="1" border="1">
<tr align="center">
<td width="50%">ID</td>
<td width="50%">Value</td>
</tr>
<tr align="center">
<td width="50%">1</td>
<td width="50%">OK</td>
</tr>
<tr align="center">
<td width="50%">2</td>
<td width="50%">OK</td>
</tr>
</table>
</div><br />
<div id="button">
<input name="Print" id="Print" type="button" value="Print Preview" onclick="printpreview();" />
</div>
</body>
</html>
[/HTML]
Oct 1 '07 #1
Share this Question
Share on Google+
7 Replies


P: 51
It's ok i have been got the solution a while ago! Here the code as folowing;

[HTML]<script language="javascript">
function printpreview()
{
var OLECMDID = 7;
/* OLECMDID values:
* 6 - print
* 7 - print preview
* 8 - page setup (for printing)
* 1 - open window
* 4 - Save As
* 10 - properties
*/
var PROMPT = 1; // 2 DONTPROMPTUSER
var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
if(document.getElementById('button').style.display ='none')
{
document.getElementById('form').style.display='blo ck';
}
WebBrowser1.ExecWB(OLECMDID, PROMPT);
WebBrowser1.outerHTML = "";
document.getElementById('button').style.display='b lock';
}
</script>[/HTML]
Oct 1 '07 #2

P: 51
But, how to hide the mainFrame if i use three frames (leftFrame, mainFrame, topFrame) and i put the code inside the mainFrame? Your help are appreciete, thanks

Regard;

Fareast Adam
Oct 1 '07 #3

acoder
Expert Mod 15k+
P: 16,027
Set the frameset's rows or cols attribute to the correct percentage to hide the frame. Show the code for the frameset.
Oct 1 '07 #4

P: 51
The topFrame and leftFrame are hidden while previewing mainFrame but i still not got an expected result, previewing only 'complaint'. Here the code as below;

[HTML]function printpreview()
{
var OLECMDID = 7;
/* OLECMDID values:
* 6 - print
* 7 - print preview
* 8 - page setup (for printing)
* 1 - open window
* 4 - Save As
* 10 - properties
*/
var PROMPT = 1; // 2 DONTPROMPTUSER
var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
window.parent.frames('mainFrame').document.getElem entById('complaint').document.body.insertAdjacentH TML('beforeEnd', WebBrowser);

window.parent.frames('leftFrame').document.body.st yle.display='none';
window.parent.frames('topFrame').document.body.sty le.display='none';

WebBrowser1.ExecWB(OLECMDID, PROMPT);
WebBrowser1.outerHTML = '';

window.parent.frames('leftFrame').document.body.st yle.display='block';
window.parent.frames('topFrame').document.body.sty le.display='block';
}[/HTML]
Oct 1 '07 #5

acoder
Expert Mod 15k+
P: 16,027
This print preview code will probably only work in IE.

What happens instead of the expected result?
Oct 2 '07 #6

P: 51
All leftFrame and topFrame contents are hidden but the problem is both size never change! What i want is to hide both frames while the specified contents inside the mainFrame is only preview not all the mainFrame contents.
Oct 2 '07 #7

acoder
Expert Mod 15k+
P: 16,027
Can you show your frameset code?
Oct 2 '07 #8

Post your reply

Sign in to post your reply or Sign up for a free account.