Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > How to use media type to not load IMG for handheld?

How to use media type to not load IMG for handheld?
Thread Tools
Zim
Senior User
Join Date: Apr 2001
Location: Cary, NC
Status: Offline
Reply With Quote
Mar 16, 2004, 07:48 AM
 
How can I use CSS, or Perl/PHP (perhaps testing an environment variable) to detect the media type and NOT load (or send) a 100k IMG for handheld users?

Thanks,
Mike
     
Clinically Insane
Join Date: Nov 1999
Status: Offline
Reply With Quote
Mar 16, 2004, 07:57 AM
 
Ideally, you'd do this:

1) Give your images a class of "nohandheld" or something similar. If you only have one image that you want to hide, give it an id of "nohandheld" instead (if it doesn't have another id already); this will run a little faster.

In your CSS, add the following:
Code:
@media(handheld) { .nohandheld { display: none; } }
If there's only one image that you want to hide, use an ID of "nohandheld" or something similar instead of a class (unless your image already has an ID, in which case simply go with that. The browser can parse this out somewhat more quickly, which is important on handhelds. Your CSS (assuming an id of nohandheld) would then look like this:
Code:
@media(handheld) { #nohandheld { display: none; } }
Note the # instead of the . That's how the browser knows to look for an ID instead of a class. The only catch to this approach is that you can only have one element with a given ID per page; this is why the browser can parse it more quickly. If you have more than one image you want to hide, use a class instead.
You are in Soviet Russia. It is dark. Grue is likely to be eaten by YOU!
     
Zim  (op)
Senior User
Join Date: Apr 2001
Location: Cary, NC
Status: Offline
Reply With Quote
Mar 16, 2004, 08:12 AM
 
Excellent. One clarification I wanted to make...

When you use display:none, that will prevent the browser from doing the download? (I was afraid it might still download it, then just not display it, which would obviously defeat the purpose ).

Thanks!
Mike
     
Dedicated MacNNer
Join Date: Nov 2001
Location: Are Eye
Status: Offline
Reply With Quote
Mar 16, 2004, 08:17 AM
 
Originally posted by Zim:
Excellent. One clarification I wanted to make...

When you use display:none, that will prevent the browser from doing the download? (I was afraid it might still download it, then just not display it, which would obviously defeat the purpose ).

Thanks!
Mike
display:none will not download. visibility:hidden will download but not display
     
Zim  (op)
Senior User
Join Date: Apr 2001
Location: Cary, NC
Status: Offline
Reply With Quote
Mar 16, 2004, 08:33 AM
 
Originally posted by registered_user:
display:none will not download. visibility:hidden will download but not display
Thanks both for the quick and informative replies!

Mike
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:02 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2