Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > Programming Articles
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
Restrict code in the templates to certain browsers.
Brad
Join Date: Nov 2001
Posts: 4,765

 

Show Printable Version Email this Page Subscription
Brad Brad is offline 02-08-2006, 10:00 PM

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 [high]is_browser[/high]. 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:

HTML Code:
<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:

HTML Code:
<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:

HTML Code:
<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
ie => Internet Explorer
mozilla => Mozilla and Mozilla based browsers.
firebird => Older versions of Firefox (below)
firefox => Firefox
camino => Camino
konqueror => Konqueror
safari => Safari
webkit => webkit based applications
webtv => Webtv
netscape => Netscape
Reply With Quote
  #2  
Old 02-09-2006, 03:12 PM
sabret00the's Avatar
sabret00the sabret00the is offline
 
Join Date: Jan 2003
Location: London
Posts: 5,268
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

nice work brad
Reply With Quote
  #3  
Old 02-09-2006, 08:13 PM
Trigunflame's Avatar
Trigunflame Trigunflame is offline
 
Join Date: Aug 2002
Posts: 742
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Good idea
Reply With Quote
  #4  
Old 05-09-2006, 07:33 AM
rob30UK rob30UK is offline
 
Join Date: Oct 2005
Location: UK
Posts: 159
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Is there any way to get to the minor version using native VB code?
Reply With Quote
  #5  
Old 05-09-2006, 04:27 PM
SaN-DeeP's Avatar
SaN-DeeP SaN-DeeP is offline
 
Join Date: Jun 2002
Location: Mumbai, India
Posts: 1,195
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
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
Reply With Quote
  #6  
Old 05-29-2006, 11:22 PM
blawson12 blawson12 is offline
 
Join Date: Nov 2005
Location: USA
Posts: 14
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ah, I was wondering how to do this! This helps alot!
Reply With Quote
  #7  
Old 06-03-2006, 03:21 PM
Gio~Logist's Avatar
Gio~Logist Gio~Logist is offline
 
Join Date: Jun 2004
Location: San Francisco
Posts: 2,575
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 07:19 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.06328 seconds
  • Memory Usage 2,258KB
  • Queries Executed 20 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)bbcode_code
  • (3)bbcode_html
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (7)post_thanks_box
  • (7)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (7)post_thanks_postbit_info
  • (6)postbit
  • (7)postbit_onlinestatus
  • (7)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete