Forum Discussion

Jeff_Brinkerho1's avatar
Jeff_Brinkerho1
Icon for Nimbostratus rankNimbostratus
Apr 09, 2010

Rquest: irule to detect if browser has javascript enabled

Our developers have requested that the ltm1500 we are using to load balance and SSL terminate our Peoplesoft environmnent also be able to determine if a client's browser has javascript enabled. If so, pass them on to the original requested pool, if not redirect them to a static HTML page that explains browser requirements.

 

 

I have searched, and have not found anyone who has done something like this. Can anyone help?

 

 

Thanks

 

Jeff

 

1 Reply

  • Hi Jeff,

    Here's a rough idea: Per browser session, do you want to use LTM to send a test response which detects whether the client has Javascript enabled? If so, you check on any requested URI to see if a custom cookie you set in the iRule is present. If it's not present, you could try to set it with Javascript (js=enabled or something). In a HTML tag, you could prompt clients who don't have Javascript enabled to make a request to a custom page. On that page, you could set the js cookie to disabled so you don't force the client through the detection process on every request. I'm not sure about the exact mechanics of trying in a single LTM generated response to set a cookie via Javascript and prompt clients who have Javascript disabled to make a new HTTP request automatically. Also, for clients who don't have JS enabled and get redirected to a new page, you'd need to figure out a way to get them back to the original page they requested. Maybe you could use the Referer header for this?

    Anyhow, hopefully this gives you an idea of the logic you could use. As far as mechanics, the iRule would be relatively simple. Here is a rough, untested idea. I guess you might also want to consider the possibility that some clients don't accept cookies.

    
    when HTTP_REQUEST {
    
        Check if this is a request to the custom URI
       if {[HTTP::path] eq "/js_disabled" {
    
          HTTP::respond 302 Location [HTTP::header Referer] Set-Cookie "js=disabled; path=\"/\";"
       }
        Check all URIs or just some? For example, just check html pages
       if {not ([HTTP::path] ends_with ".html")}{
    
           This is a URI we don't want to check for Javascript support on
           Exit this event in this iRule
          return
       }
        If we're still in the iRule, we're going to check for Javascript support as indicated by a cookie
       switch [HTTP::cookie js] {
          "enabled" {
             pool js_pool
          }
          "disabled" {
             pool nonjs_pool
          }
          default {
              Need to test if the client supports Javascript by trying to set a cookie named js
      If the client doesn't have Javascript enabled, force them to make a request to a custom URI 
      which sets a cookie indicating the client doesn't have JS enabled (for example: /js_disabled)
     HTTP::respond 200 {...}
          }
       }
    }