in reply to IE specific conditional comments in header of CGI.pm
pashanoid, importing the :html2 paramater after use CGI: will enable the comment and Link methods to be utilised. Using these you can construct your conditional comments and use the start_html method, for example:
use strict; use warnings; use CGI qw/:html2 -noxhtml/;
sub linkstyle(){ Link { -rel => 'stylesheet', -type => 'text/css', -src => $arebelong.'script/ie2.css', -media => 'all' } };
print $q->start_html( -head=>[ comment('[if lte IE 6]>'."\n".&linkstyle.'<![endif]') ] );
#! /usr/bin/perl use strict; use warnings; use CGI qw/:html2 -noxhtml/; use CGI::Pretty; my $allyour = "http://localhost/"; my $arebelong = "http://localhost/"; my $normalstyle = "http://localhost/"; my $normalscript = "http://localhost/"; my $q = CGI->new(); print $q->header(-type=>'text/html'); sub linkstyle(){ Link({-rel => 'stylesheet', -type => 'text/css', -src => $arebelong.'to/us/script/ie2.css', -media => 'all' }) }; print $q->start_html( -lang=>'en-GB', -title=>'conditionalcomments or hot css buns', -head=>[ Link({-rel => 'stylesheet', -type => 'text/css', -src => $allyour.'buns/script/ie8.css', -media => 'all' }), comment('exists (conditional comment method) ? find : next'), comment('[if lte IE 6]>'."\n".&linkstyle."\n".'<![endif]'), ], -style=>{-src=> $normalstyle.'style/w3m.css', -media=>'all'}, -script=>{-type=>'text/javascript', -src=> $normalscript.'script/nom/nom.js'} ); print $q->h1('HelloWorld!!'), $q->end_html; exit 0;
This returns the various link elements to stylesheets as required.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html lang="en-GB"><head><title>conditionalcomments or hot css buns</t +itle> <link type="text/css" media="all" src="http://localhost/buns/script/ie +8.css" rel="stylesheet"> <!-- exists (conditional comment method) ? find : next --> <!-- [if lte IE 6]> <link type="text/css" media="all" src="http://localhost/to/us/script/i +e2.css" rel="stylesheet"> <![endif] --> <link rel="stylesheet" type="text/css" href="http://localhost/style/w3 +m.css"media="all"> <script src="http://localhost/script/nomnom.js" type="text/javascript" +></script> </head> <body> <h1> HelloWorld!! </h1> </body> </html>
One thing I am not too sure about is whether the 'rel' attribute not being first in order within the link element will make a difference, I have a niggle that it is supposed to be first from somewhere but not sure. However this occurs when the link method is called both straightforwardly within the head method and when called as a return from a sub so probably is ok.
I would question why you are trying to produce conditional comments from a server cgi script though. As I would expect these are mostly used in shtml. Unless of course you are producing static shtml for future usage. Then though, wouldn't there now be a need to ensure the correct DTD is in use? Would be interesting to know.
Coyote
|
|---|