Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Font color won't change for onbeforeprint

Status
Not open for further replies.

humbleprogrammer

Programmer
Oct 30, 2002
315
US
Hello,

I have a function that hides certain elements in a page, changes the background to white and is supposed to change the font color to black when the page is printed. Everything works except it doesn't change the font color. Below is my code. Can someone glance it over and shed some light?

<script>
function simplealert(){
//Fires off the alert in the body tag.
alert('Commenced printing!')
}
window.onbeforeprint=simplealert

function printformat(){
//Make the document background white and font black
document.bgColor=&quot;white&quot;
document.body.style.background=&quot;white&quot;
document.body.style.color=&quot;black&quot;

//store all elements with id=remove to &quot;remove_el&quot;
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.style.display='none'
}
}

function revertback(){
//Reload the window
setTimeout(&quot;window.location.reload()&quot;,50)
}

window.onbeforeprint=printformat
window.onafterprint=revertback
</script>

Thanks in advance!
 
Nevermind, I am lame! After spending an hour on this and then posting it here, I realized I had the font color set to white in my CSS for <td>. After accounting for the <td> in my function it worked.
 
Looks like a lot of work when you can just run two stylesheets, one for screen and one for print. Or wrap the preferred styles in @media blocks.

Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top