Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    May 2003
    Location
    MI
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Having trouble using document.write with server side include

    I am having trouble with a script that sniffs the browser for IE or non-IE, then selects a server side include based on that. I suppose there might be a way to do this with a javascript include, but I think it would be a lot simpler if I could use the SSI - the include is huge and complex.

    The script is below

    Code:
    <SCRIPT LANGUAGE="JavaScript">
    // Browser sniff -- the following code does a very simple browser check and rates the 
    //     browser as either Internet Explorer on a Win32 platform or not, so that we 
    //     know to use the ActiveX model, or the plug-in Model.
    var sBrowser = navigator.userAgent;  
    if ((sBrowser.indexOf("IE") > -1) && (navigator.platform == "Win32"))
        {
         sBrowser = "IE";
         }
     else {
         sBrowser = "nonIE";
         } 
    
    if (sBrowser == "IE") 
    			{  
    document.write('IE');
    document.write('<!--# include virtual="includes/safety.htm" -->');
    }
    
     else if (sBrowser == "nonIE")
    
    			 { 
    			 document.write('non-IE');
    			 document.write('<!--# include virtual="includes/safety_nonIE.htm" -->');
    			 }
    		  </script>
    I have tried escaping the ! with \ but it makes no difference. I am fairly sure the browser is seeing the <!-- as the start of a comment, and ending the processing of the script right there. I have tried all sorts of escape techniques!

    I think my syntax for the if - else statement is right because the first document.write does execute, and you will note either "IE" or "nonIE" appears in the middle of the page.

    A test page is here

    Any help getting this to work would be appreciated!

    Thanks

    Ellen

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    You can't do that. SSI are evaluated on the server so they are already executed before the browser renders the page. Maybe you can try this
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #3
    New Coder
    Join Date
    May 2003
    Location
    MI
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Oh, it's one of THOSE types of things...

    Thank you so much - I will try your suggestion and post back here.

    Ellen

  • #4
    New Coder
    Join Date
    May 2003
    Location
    MI
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts

    YAY!!! it works! Conditional SSI

    Here is the example
    Conditional SSI test
    Try it in IE for PC and Firefox or Safari or something else.

    (I know the non-ie version has some issues, ignore the playlist error messages!)

    Here is the code:
    Code:
    		
    <!--#if expr="${HTTP_USER_AGENT} = /MSIE/" -->
    <!--# include virtual="includes/safety.htm" -->
    <!--#else -->
    <!--# include virtual="includes/safety_nonIE.htm" -->
    <!--#endif -->
    Basically this chooses a server-side include based on the user agent.

    for more information on this see these links:

    Conditional SSI by John Miller

    and
    Webmaster's Guide to Server Side Includes: Conditional SSI


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •