Click to See Complete Forum and Search --> : print css on external files


HJC
12-14-2009, 09:11 PM
I have a print button in the page
<center><script>
document.write("<input type='button' " +
"onClick='window.print()' " +
"class='printbutton' " +
"value='Print This Page'/>");
</script>
</center>
I can call <style type="text/css" media="print">
.printbutton {
visibility: hidden;
display: none;
}
body{
font-size: 15px;
font-family: Arial, Helvetica, sans-serif;
margin-left:0.5em;
margin-right:0.5em;
}
</style> but when this part of code be put on external an call it ,it did not work , why
<link href="css/print.css" media="print" rel="stylesheet" type="text/css" />

HJC
12-14-2009, 09:18 PM
I have print able web form , need to decide where to break the page , but on Ie the shrink to fit is different with firefox , I add <style type="text/css" media="print">

body{
font-size: 15px;
font-family: Arial, Helvetica, sans-serif;
margin-left:0.5em;
margin-right:0.5em;
}
</style> in my web page , but still Shink to fit is different in these two browns .
is that possible to set the stand margin whatever the user use what kind of browns or print setting???:(

Fang
12-15-2009, 12:46 AM
You can not change the page margin for printing. Do not confuse this with body margin, which is completely different.

HJC
12-15-2009, 01:36 AM
thank you,
How about put on external??
<center><script>
document.write("<input type='button' " +
"onClick='window.print()' " +
"class='printbutton' " +
"value='Print This Page'/>");
</script>
</center>

Fang
12-15-2009, 02:16 AM
Why are you using an inline script to add html? It makes no sense.

HJC
12-15-2009, 02:28 AM
Then , what is the best way to handle this?

Fang
12-15-2009, 02:35 AM
What is wrong with html? No need for JavaScript.

HJC
12-15-2009, 07:42 PM
Thank you

rnd me
12-17-2009, 12:07 AM
What is wrong with html? No need for JavaScript.

html alone would present a non-working button to anyone without javascript, wheras a javascript-added button would only present a button if the button would work as expected when clicked...

that said, i would typically set an id on the input (perhaps btnPrint), and hide it in css by default ( #btnPrint {display:none;}).

then, anywhere in javascript, even an external file, i can say:
document.getElementById("btnPrint").style.display="inline";

this is almost as good as actually adding the button in javascript, usability-wise.

The only problem with un-hding it in js it when someone has no javascript or css available, the busted button would show up. that's probably a small % of users, and they can always use the browser's print feature...