Helpful Information
 
 
Category: Programming Articles
Restrict code in the templates to certain browsers.

This thread will teach you how to restrict code in the templates to certain browsers.

Before we begin

This method is not a substitute for proper html and css. Also the way we determine the browser the client is using can easily be spoofed, it's not hard to make vBulletin think firefox is really IE for example.

In other words this method should only be used when there is no other way to get the job done.

The good stuff

There is a function within the vBulletin source code call is_browser. With this function we can determine what type of browser the client is using, and which version of the browser the client is using.

In any given template, you can use this code to display a short message to clients that use Internet Explorer:

<if condition="is_browser('ie')"><b>You are using Internet Explorer</b></if>

We can also display a message based on the version number of Internet Explorer:

<if condition="is_browser('ie', 6)"><b>You are using Internet Explorer version 6</b></if>
<if condition="is_browser('ie', 5)"><b>You are using Internet Explorer version 5</b></if>

So why is this useful? Well lets say for some odd reason you do not support Internet Explorer 5 or lower on your site and you would like to display a short message to users visiting your site with that browser. Well we can do something like this:

<if condition="!is_browser('ie', 6)"><b>mysite.com only supports Internet Explorer 6.0 and higher, please upgrade your browser</b></if>

This conditional would display "mysite.com only supports Internet Explorer 6.0 and higher, please upgrade your browser" in bold to any client running Internet Explorer version 5.5 or lower. Also before anyone brings this up, no it will not display the message to clients using Internet Explorer version 7. In other words the function is coded in such a way that your code is future proof. :)

Here is a list of browsers supported by the is_browser function. The call sign is on the left (the name you should use in the function call), the browser name that call sign relates to is on the right.

Supported browsers

opera => Opera (http://www.opera.com/)
ie => Internet Explorer (http://www.microsoft.com)
mozilla => Mozilla (http://www.mozilla.org/products/mozilla1.x/) and Mozilla based browsers.
firebird => Older versions of Firefox (below)
firefox => Firefox (http://www.mozilla.com/firefox/)
camino => Camino (http://www.mozilla.org/products/camino/)
konqueror => Konqueror (http://www.konqueror.org/)
safari => Safari (http://www.apple.com/safari/download/)
webkit => webkit (http://webkit.opendarwin.org/) based applications
webtv => Webtv (http://developer.msntv.com/Tools/WebTVVwr.asp)
netscape => Netscape (http://browser.netscape.com/)

nice work brad :)

Good idea :)

Is there any way to get to the minor version using native VB code?

There is a function within the vBulletin source code call is_browser. With this function we can determine what type of browser the client is using, and which version of the browser the client is using.
thanks brad :)

Ah, I was wondering how to do this! This helps alot!

Ah. I believe this will be very useful:
<if condition="!is_browser('firefox')"><b>Get FireFox Now!</b></if>










privacy (GDPR)