...

View Full Version : remove elements in web page before printing



amalpartout
07-15-2007, 02:36 PM
Hello,

I am French. sorry if my english is bad.

I have a problem. I want remove somethink in web page befor printing. I found some exemple but it work with IE7 but it don't work with Firefox.

<!-- DEBUT REMOVE PRINT-->
<!--http://www.javascriptkit.com/-->
<script language="JavaScript">
function removeelements(){
//store all elements with id=remove to "remove_el"
var remove_el=document.write.remove
var remove_el=document.all.remove
//if there is only one element with id=remove
if (remove_el!=''&&remove_el.length==null)
remove_el.style.display='none'
else{
//for each element with id=remove
for (i=0;i<remove_el.length;i++)
remove_el[i].style.display='none'
}
}
function revertback(){
setTimeout("window.location.reload()",50)
}
window.onbeforeprint=removeelements
window.onafterprint=revertback
</script>
<!-- FIN REMOVE PRINT-->

I know that "window.onbeforeprint" is not supported by firefox. it work well with IE7. I put id=remore in each balise



I have a second solution but I don't know how it don't work

<link href="afpca.css" rel="stylesheet" type="text/css" />
<link href="imprimante.css" rel="stylesheet" type="text/css" media="print" />

in file imprimante.css i write :
#remove {
display: none;
}

my print button ;
<input name="Imprimez" onclick="window.print()" class="formbutton" id="Imprimez" value="Imprimez" type="button" />

It don't do anythink . grrr !! but if I use "imprimante.css" with using google developpers toolbar it's ok.

Please , what I miss in my web page

Thank you very much for answers.

Amalpartout

ronaldb66
07-16-2007, 08:34 AM
You're definitely on the right track; a print stylesheet can be used to suppress certain elements you don't want to print.
However, the style rule in your print style sheet (imprimante.css) says:

"set all elements with id="remove" to not displaying". I see no id="remove" in your button... Either add the id, or change the selector in the rule.

also, you may need to set a specific media type on the default style sheet (afpca.css) as well.

More information on print stylesheets can be found in Eric Meyer's article " CSS Design: Going to Print (http://www.alistapart.com/stories/goingtoprint/)" on ALA.

Dyolf
07-16-2007, 02:26 PM
Why don't you just make a Printer Friendly Version page and use a print button?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum