473,385 Members | 1,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Editing CSS in @media print

Hello,
I am trying to edit a CSS rule with Javascript, which is for printing. Thus

@media print
{
#footer { display: none; }
}

I would like to be able to access the display attribute of #footer, but
I can't get to it. If I edit the element.style.display property then
that changes it, but for all the stylesheet, not just print.

Anybody?
Thanks

Nick
Nov 28 '05 #1
3 5411
VK

Nick wrote:
Hello,
I am trying to edit a CSS rule with Javascript, which is for printing. Thus

@media print
{
#footer { display: none; }
}

I would like to be able to access the display attribute of #footer, but
I can't get to it. If I edit the element.style.display property then
that changes it, but for all the stylesheet, not just print.


You did not specify where is your CSS table: inline or from an external
file (in the latter case it gets even more funny :-).

Presuming you have an inline style declaration:

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<style>
@media all {
body { background-color: white; }
}

@media screen {
#footer { display: block; }
}

@media print {
#footer { display: none; }
}
</style>
<script type="text/javascript">
function test() {
// To get media.print::footer.display in IE:
//alert(document.styleSheets[0].rules[2].style.display);

// To get media.print::footer.display in FF:
// alert(ss.cssRules[2].cssRules[0].style.display);

// To get media.print::footer.display in Opera:
// Have no idea: window and document seems do not expose
// any scriptable object for style (?)

// Other browsers may be even more amazing (?)
}
</script>
</head>

<body onload="test()">
<div id="footer">Footer</div>
</body>
</html>

I would suggest to reverse your logic: instead of patching the CSS
table - change style attributes of elements themselve using className()
and/or setAttribute() methods. This way you'll get much more reliable
anduniversal solution.

Nov 28 '05 #2
Nick wrote:
I am trying to edit a CSS rule with Javascript, which is for printing.


Not considering that this is not generally possible, why would you want to?
The very idea of CSS rules for printing is that no other technique would be
required for adequate presentation.
PointedEars
Nov 28 '05 #3
Thomas 'PointedEars' Lahn wrote:
Nick wrote:
I am trying to edit a CSS rule with Javascript, which is for printing


Not considering that this is not generally possible, why would you want to?
The very idea of CSS rules for printing is that no other technique would be
required for adequate presentation.


Indeed. It was all a bit of a hack (and still is to some extent), after
using JS to optionally show a footer (because it uses JS to position it
(bad I know), and it'd be better non-JS to have it hidden than displayed
in the middle of the page).

Using <noscript> tags to achieve the effect instead.

Thanks
Nov 28 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: geotso | last post by:
Hi I'm trying to hide from printing a specific element of a page but I don't know how (and if) I could. Here is an example of what I'm trying to do: <h1>Hidden in print mode</h1> <p>Also...
3
by: Sonya | last post by:
Dear list; I am a css newbie, and hope you can help. I am trying to make my page print out horizontal when user hits a print button in my page. the print button invokes javascript print.window()...
2
by: Wim van Iersel | last post by:
I hope somebody knows what I´m doing wrong here I have a page with two stylesheets: - default.css media="screen, print" http://www.tilburg.nl/development/stylesheets/default2.css - print.css...
1
by: Garmt de Vries | last post by:
For a long time, I've used CSS to style my webpages, but only for media "screen" and "print". Now I've started looking into styling them for other media like "projection" and "handheld". I'd be...
0
by: Steven Kobes | last post by:
On this page, IE ignores the width in the media='print' stylesheet: http://thekobes.com/maxwidth/ As a result, the text appears in Print Preview with width 30em instead of auto (unless the...
11
by: Wolfgang Meier | last post by:
Hi, I really hope I'm not hitting a frequently asked question here, because I think almost every author must have made that decision. Anyway, here goes: Would it be better to write one global...
2
by: Viken Karaguesian | last post by:
Hello all, I'm a little confused on how to implement @media to make some web pages print better. From what I've been able to read so far, I need to set the @media rules as the top items in my...
1
by: tdartt | last post by:
Howdy! I'm fairly new to using css. I have two style sheets: <LINK href="printstyle.css" type="text/css" rel="stylesheet" media="print"> Which has (for example): .dgAltLine { display: none;...
10
by: Ed Jay | last post by:
I do not want to load two style sheets for screen and print media. I'm having difficulty grasping the use of the @print statement, or its syntax. Would someone please provide a simple explanation....
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.