 |
 |
How to use media type to not load IMG for handheld?
|
 |
|
 |
|
Senior User
Join Date: Apr 2001
Location: Cary, NC
Status:
Offline
|
|
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
|
|
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!
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Apr 2001
Location: Cary, NC
Status:
Offline
|
|
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
|
|
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
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Apr 2001
Location: Cary, NC
Status:
Offline
|
|
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
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|