RootsWeb.com Mailing Lists
Total: 1/1
    1. Re: [FreeHelp] Serving different content for different browsers
    2. Barry Carlson
    3. As mentioned in my earlier post, here is the SSI content of the page I posted. SSI is capable of handling quite complex conditional expressions where a question is posed and if TRUE a result is given, but if FALSE a further question is asked, etc.. and if no result is forthcoming a default outcome will result. In the example below, we are looking to add the class="ieOld" to the <html> tag IF the browser identifies as MSIE 5 through 9. If that expression is TRUE, <html class="ieOld"> is inserted by the server and the expression ends. If the initial expression was FALSE then using ELIF (else-if) a test is now made for MSIE 10 or greater. If that expression is TRUE, <html class="ieNew"> is inserted by the server and the expression ends. If neither of the previous attempts were TRUE, the expression jumps to ELSE and inserts the default value of <html>. The same applies to the second expression which inserts the appropriate statement plus the browser User-Agent in the body of the page. As we use HTTP_USER_AGENT often, it has been SET as a variable, i.e. #set var="uA" value="$HTTP_USER_AGENT". In the first expression we check the the HTTP_USER_AGENT for MSIE 5 - 9 and as we are using regular expressions the string we are looking for is between the / and /. The numbers that will match can be any values that fall within the range [5-9], or in the case of the second expression, a number matching 10 or greater - [{10,}]. <!--#set var="uA" value="$HTTP_USER_AGENT" --> <!--#if expr="($uA=/MSIE [5-9]/)" --> <html class="ieOld"> <!--#elif expr="($uA=/MSIE [{10,}]/)" --> <html class="ieNew"> <!--#else --> <html> <!--#endif --> <!--#if expr="($uA=/MSIE [5-9]/)" --> This browser is an Internet Explorer version between 5 and 9 <!-#echo var="uA" --> <!--#elif expr="($uA=/MSIE [{10,}]/)" --> This browser is Internet Explorer version 10 or newer <!-#echo var="uA" --> <!--#else --> This browser is NOT an Internet Explorer version <!-#echo var="uA" --> <!--#endif --> The actual source code for the page is here:- http://freepages.rootsweb.com/~bristowe/ssi-demo-code.html - and you can copy & paste into a text editor and save with a filename of your choice. Unless you have a local Apache server, you will need to place it on a server running SSI to check it works. If you want your source code not to show blank lines where SSI data has been inserted, you will need to make all the code within an expression appear as one line. Most good text editors will show it as a single line number if you have organized it correctly. The working file is here:- http://freepages.rootsweb.com/~bristowe/ssi-test.html Barry

    05/24/2012 04:18:38