You Are Here:

Community: Wiki

This page was last modified on 29 September 2009, at 04:28.

How to switch CSS styles

From Forum Nokia Wiki

Reviewer Approved   

This "How to" article functions as a workaround in cases where the header agent is not supplied by the browser. With the OOS 3.0 full web browser (Nokia Web Browser) - the browser does not supply this information. Later versions of the Browser are likely to make that declaration.

The Nokia Web Browser renders Web pages in their full layout and utilizes a MiniMap feature for efficient use of a large Web page. However, sometimes it may necessary or feasible to recognize that the user is using a mobile browser. This information can be used for various purposes, for example:

  • Providing an alternative CSS stylesheet (for an alternative layout or text sizes, for example):
    • Omitting elements or objects from the page shown on the mobile browser
    • Providing an alternative navigation
    • Offering lighter versions of graphics to reduce download speeds

First declare the alternative styles:

<link rel="stylesheet" href="styles/main.css" 
type="text/css" media="all" title="Main">
<link rel="alternate stylesheet" href="styles/mobile.css"
type="text/css" media="all" title="Mobile">


Functionality is implemented with JavaScript objects (screen.width, screen.height) that detect if the user is using a QVGA-sized browser. After the detection, the browser is instructed to use an alternative CSS stylesheet. Upon initial page loading, the page uses the getScreenSize function to check the display size on the mobile device:

if(getScreenSize(240, 320)) {
generateMobinav();
setActiveStyleSheet('Mobile');
}
If the mobile display size corresponds to the setting (in this case, QVGA),
the page generates the additional navigational tool (function
generateMobinav) and automatically switches the page to use the Mobile
stylesheet. The function below loads the alternative stylesheet (note that
the name of the stylesheet is used as an argument and originates from the
function call).
 
/* =v==== STYLESHEET SWITCHER =====v= */
 
function setActiveStyleSheet(title) {
 
if(document.getElementsByTagName) {
 
var i, a, main;
 
for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
 
if(a.getAttribute("rel").indexOf("style") != -1 &&
a.getAttribute("title")) {
 
a.disabled = true;
 
if(a.getAttribute("title") == title) a.disabled = false;
}
}
}
return false;
}


Note that if you decide to use an alternative layout for the mobile browser, let the user know it and provide him or her with the possibility to switch to the full version.



Related Wiki Articles

No related wiki articles found

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2findeE78E2ephpE2fHowE5ftoE5fswitchE5fCSSE5fstylesX qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqfntypeZWikiContentQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtopicQUqfnTopicZbrowsingQ qfnZtopicQUqfnTopicZhtmlQ qfnZtopicQUqfnTopicZwebE5ftechnologyQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qfnZtypeQUqfntypeZWikiContentQ qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqfntypeZWikiContentQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ