The attached add-on files may be out of date. Please visit Devot-ee for the latest versions.
Hi,
I wrote a simple plugin named “Browser Sniff” which allows to find browser name and version.
Using it you can write the code such as this:
{exp:browser_sniff}
{if browser_name!="ie"}
Some code
{if:else}
Some other code
{/if}
{/exp:browser_sniff}
Or you can write code such as this:
{exp:browser_sniff}
{if browser_name=="ie" AND browser_version<=6}
Some code
{if:else}
Some other code
{/if}
{/exp:browser_sniff}
You can also use {browser_name}, {browser_version}, {browser_subversion} and {os} variables inside the tags to output the detected browser name, version and OS:
{if browser_name=='ie' AND browser_version<=6}
Browser name: {browser_name}
Browser version: {browser_version}
Browser subversion: {browser_subversion}
OS: {os}
{/if}
You can use {browser_name}, {browser_version}, {browser_subversion} variables both inside and outside conditionals:
{exp:browser_sniff}
{if browser_name!="ie" AND browser_version<7}
Browser name: {browser_name}
Browser version: {browser_version}
{/if}
{/exp:browser_sniff}
Possible values of {browser_name} variable are: ie (internet exploder), op (opera), konq (konqueror), saf (safari), moz (Gecko browsers), ns4 (mozilla/4), other (other browsers).
Possible values of {os} variable: win (windows), mac (Macintosh), linux (Linux), other (other OS).
Notice about version numbers: for Gecko based browsers this plugin outputs Gecko version number and for Safari - Webkit version number (On Safari and Webkit version numbers see here).
Is there any need for such code and such plugin?
It seems to me that possibility to write such code may be handy if you want to pass some piece of CSS or HTML to some browsers and another set to other browswers (most probably there will be a need to differentiate between Internet Explorer and other browsers). Although many notable persons say that browser detection is obsolete technique I constantly find nothing better than employing it. Perhaps browser detection and forking of code will be obsolete when Microsoft will release browser better than IE7 and IE6 and IE7 will be dead, but it is very long way to go.
If there is a need for browser detection, is there a need to wrap Browser detection function into plugin? Why not using PHP function directly in templates?
I have tried this and got very strange effects: the function which now wrapped in plugin works correctly did not work as plain PHP in stylesheet templates. There is a thread about it.
Credits: Harald Hope, author of Lightweight PHP Browser Detector Script, which is used in Browser Sniff plugin; Timon Royer (eexperience), [email protected] who added support for the use of variables {browser_name} and {browser_version} outside conditionals.
Any comments and suggestions appreciated.
Nice work! I like this plugin.
Examples: Warning for old IE6
{exp:browser_sniff} {if browser_name=="ie" AND browser_version<=6} ATTENTION! This site is optimized for the actual IE, please update your browser. Microsoft Update Website/images/system/browser-ie.gif {/if} {/exp:browser_sniff}
Specific Bookmark
{exp:browser_sniff} {if browser_name=="ie"} {/if} {/exp:browser_sniff} {exp:browser_sniff} {if browser_name=="moz" OR browser_name=="ns4"} {/if} {/exp:browser_sniff}
Unfotunately I don’t know how to set an Opera Bookmark Link.
Hi Ronin,
Should there be some code in where you have the ’s above. You mention that this is for bookmarks. Do you mean this will auto-add in a bookmark for the site? If so then I think maybe there is some code missing there. Maybe the forums here have stopped certain text from being shown?
Best wishes,
Mark
P.S. Nice plugin by the way Laisvunas, well done 😊
the code works in the preview, and online it is deleted
replace all underlines in the link to use it
{exp:browser_sniff}
{if browser_name=="ie"}
<a href="http://ja_vascr_ipt:wind_ow.exte_rnal.A_ddFavo_rite%27url%27,">_/images/system/site_tools_bookmark.gif <strong>add to favorites</strong></a>
{/if}
{/exp:browser_sniff}
{exp:browser_sniff}
{if browser_name=="moz" OR browser_name=="ns4"}
<a href="http://ja_vascr_ipt:win_dow.sid_ebar.a_ddPa_nel%27title%27,">_/images/system/site_tools_bookmark.gif <strong>add to bookmarks</strong></a>
{/if}
{/exp:browser_sniff}
If you have any <sc*ipt type=”“> type of text then you will need to swap out one of the letters for something else or place spaces between the start and end of the tags like I have shown just now so either :
<sc*ipt type="">
or
< script type="" >
Please remove the spaces after the opening tag and before the closing tag before using this code
Something like that should hopefully do it for you?
Best wishes,
Mark
Hi Ronin and Mark,
I am glad that you find this plugin useful.
Browser detection script I used in this plugin is very simple, but it seems to me that for most practical purposes it is good enough.
If someone would need more powerful browser detection, it is very easy to find more powerful function and wrap it into the plugin analogously I have done in Browser Sniff.
Hi Laisvunas, just wanted to say thank you. This is exactly what I need. I want to use the balupton jquery lightbox but only the older version works with IE6 and only the newer version looks good with IE7. Thanks for your efforts. I really appreciate your efforts, please keep up the good work!
Thanks, Timon
Hiya,
This is from the plugin notes :
Place the following tags in any of your templates:Place between these tags browser detection code such as this:{exp:browser_sniff}{/exp:browser_sniff}
Possible values of browser_name variable: ie (internet exploder), op (opera), konq (konqueror), saf (safari), moz (Gecko browsers), ns4 (mozilla/4), other (other browsers).{if browser_name=='ie' AND browser_version<=6} some code {/if}
Hope that helps.
Best wishes,
Mark
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.