Doug Rau
This user hasn't shared any biographical information
Homepage: http://www.iphouse.com/
Posts by Doug Rau
alternate stylesheets, part 5
May 21st
finally, putting our website skin library to use.
stylesheets are linked in the <head> section of an HTML page. first, we link any unnamed stylesheets. these stylesheets are always active, and provide any style instructions for your page, regardless of which skin may be chosen. for example, you might always use the same body fonts, or a stylesheet intended for print media might hide all the decorative and navigational elements of the page.
alternate stylesheets, part 4
May 19th
we now have the pieces necessary to provide several alternate skins for a website, and provide a visitor with the means to choose one and have it apply across your entire website. finally, a few functions to tie all these pieces together into a library.
the init_skin() function must be invoked sometime after the named stylesheets are defined, but preferably before the page content is loaded, so that the appropriate stylesheets are already enabled when the web browser begins drawing the web page. this is most easily accomplished by including our javascript library in the HTML head section after the stylesheets, and calling init_skin() therein.
alternate stylesheets, part 3
May 17th
just a brief update, today. looking ahead a little bit, we’re going to need some means of keeping track of which alternate stylesheet the visitor has chosen. and so, some basic cookie functions. there are, of course, more sophisticated libraries available for managing browser cookies, which could be used instead.
alternate stylesheets, part 2
May 13th
the previous post might raise the question, why are we interested in named stylesheets? HTML pages can have two different types of stylesheets linked to them. stylesheets with no title attribute are persistent, and are always applied to the page. stylesheets with a title are alternative, and a browser can choose which one is applied. one of these should have a relation attribute of rel=”stylesheet” which indicates the default (preferred) stylesheet, while the others have rel=”alternate stylesheet”. with some clever use of CSS, you can use this to provide several alternate “skins” for your website. with a browser which supports it, or some clever use of javascript, you can provide a visitor with the means to choose one and have it apply across your entire website.
thus, javascript code to obtain a list of named stylesheets. it works by using the prototype function $$() to get a list of all link elements in the page, then selects only those which are matched by the named_link() function, and finally maps those through the link_meta() function. named_link() checks whether a link’s relation attribute includes the fragment ‘style’, and whether it has a (not empty) title attribute. link_meta() returns an anonymous object containing a link element and its title attribute (which we’re most interested in).
alternate stylesheets, part 1
May 10th
first, a bit of javascript code to obtain a list of named stylesheets linked to an html web page. it uses several prototype functions to streamline the code, and to address any browser quirks in getAttribute(). and since we’re particularly interested in the title, we actually build a list of anonymous objects, each of which contains both a stylesheet link element and its title attribute.