473,387 Members | 1,504 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,387 software developers and data experts.

Setting styles dynamically only for @media screen

I have a site where I am setting a style dynamically, using the JS
statement:

obj.style.backgroundImage = 'url(img/bak_page.jpg)';

where 'obj' is either document.getElementById(id), or document.all[id],
depending on browser support.

This works just fine, with just one small problem: I want to set the style
ONLY for screen media, not for printer media; the above statement appears to
apply the style to all media.

In CSS I have previously set the style for print media using code of the
form:

@media print
{
html#html { background-image:none; }
}

and this works just fine (it prevents printing of a page's background image
when printing) UNLESS I later dynamically change the style using JS.

How can I dynamically change the style only for a specified medium?

Jul 20 '05 #1
1 2865

"C A Upsdell" <cupsdell0311XXX@-@-@XXXrogers.com> wrote in message
news:bB*****************@news04.bloor.is.net.cable .rogers.com...
I have a site where I am setting a style dynamically, using the JS
statement:

obj.style.backgroundImage = 'url(img/bak_page.jpg)';

where 'obj' is either document.getElementById(id), or document.all[id],
depending on browser support.

This works just fine, with just one small problem: I want to set the style ONLY for screen media, not for printer media; the above statement appears to apply the style to all media.
Right, you're not changing the rules, you're overriding them by setting a
property directly. You could try to use the CSS-DOM
(http://www.w3.org/TR/DOM-Level-2-Style/) to change the rule for only one
particular medium. Or, if you have an element somewhere that is affected by
a static property that you've made dependent on the medium, you could check
the value of that property to determine what the actual medium is, and
conditionally set the background image based on that.


In CSS I have previously set the style for print media using code of the
form:

@media print
{
html#html { background-image:none; }
}

and this works just fine (it prevents printing of a page's background image when printing) UNLESS I later dynamically change the style using JS.

How can I dynamically change the style only for a specified medium?


Jul 20 '05 #2

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

Similar topics

0
by: Soobrassen Thoplan | last post by:
Hi to all I'm a vb dot net programmer and would like to know how i can chage the resolution of an screen dynamically and reset it when the user exit my software. Actually i can do it with vb 6.0...
1
by: John | last post by:
Hi all, Any takes on the above, please? Regards John.
3
by: sagar | last post by:
Hello everyone, I am developing a AJAX based IM application. I use javascript to dynamically generated small windows using nested <div> within the web-page. I use the following ways to set...
2
by: maflatoun | last post by:
Hi everyone, I have the following web user control. I like to set the properties dynamically without using page.databind. <uc1:partnerdownloads id="Partnerdownloads1" PropDomain="<%= Domain...
3
by: olakara | last post by:
hi everybody, i have a problem.. i get some html through ajax from a sevlet. before displaying it on screen i dynamically create a DIV element using createElement. I specify the CSS for this DIV as...
0
by: vermarajeev | last post by:
Hi guys, There is an option in MDI where I can select a media player component. Now I have a gif file which has some animated image. How do I set the background for media player to *.gif image???...
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;...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.