We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Plugin: Browser Sniff

Development and Programming

Rob Quigley's avatar
Rob Quigley
236 posts
17 years ago
Rob Quigley's avatar Rob Quigley

I gave this a try using this code

{exp:browser_sniff}
{if browser_name=="saf" AND browser_version<3}
Some code
{/if}
{/exp:browser_sniff}

and it didn’t work for me. I used a lower level safari browser 1.3 and 2 and neither was detected as being a lesser version of 3 (or 3.1). In a separate test it detected both browsers as being safari though.

       
eexperience's avatar
eexperience
56 posts
17 years ago
eexperience's avatar eexperience

Did you check what you get with the following?

{exp:browser_sniff}

browser name: {browser_name}

browser version: {browser_version}

{/exp:browser_sniff}

Also you might want to try what $_SERVER[“HTTP_USER_AGENT”] in general is showing as a difference between the browser versions. Here’s a test page for this: http://sqa.fyicenter.com/Online_Test_Tools/__Show_Web_Browser_Information.php

       
Rob Quigley's avatar
Rob Quigley
236 posts
17 years ago
Rob Quigley's avatar Rob Quigley

Thanks for the suggestions.

I’m not receiving any info back in the template using these plugin tags below with any of the safari browsers:

{exp:browser_sniff}

browser name: {browser_name}

browser version: {browser_version}

{/exp:browser_sniff}

I went to that browser detection page .(JavaScript must be enabled to view this email address) with Safari 3.1 browser and a 1.3.2 browser. I took screen shots of the version info detected and attached a combined image of both below (one on top is the 3.1 version).

Basically, it looks like it detects a version number for the 3.1 browser but not for the earlier ones. It does provide other numbers for the browsers (525.13 & 312.6) but I wasn’t having any luck trying to use the conditional with those.

       
eexperience's avatar
eexperience
56 posts
17 years ago
eexperience's avatar eexperience

I had a look at the code at how the needed functionality can be added.

So I added three lines of code to accomplish what we want here. Now you get return values for {browser_name} and {browser_version}. This way you can check what gets detected. I’ve attached a new version to this post and I’ve updated the plugin documentation.

I’m no programmer and I don’t know much about PHP, I just browsed the PHP and EE developer docs for a while to figure out how I could return the conditionals evaluation and swap the template variables content. Looks like it turned out well. If someone feels I missed something please let me know.

The following should now work as expected:

{exp:browser_sniff}

browser name: {browser_name}

browser version: {browser_version}

{/exp:browser_sniff}

Cheers, Timon

       
Rob Quigley's avatar
Rob Quigley
236 posts
17 years ago
Rob Quigley's avatar Rob Quigley

Nice! I’m going to check this out in a little bit.

       
eexperience's avatar
eexperience
56 posts
17 years ago
eexperience's avatar eexperience

Let me know how it works for you. The version returned is the Safari build version not the WebKit version as you can see. You might find this handy for defining the right number range Safari and WebKit Version Information

       
Rob Quigley's avatar
Rob Quigley
236 posts
17 years ago
Rob Quigley's avatar Rob Quigley

Yes, that’s it, works great. And that page with browser version history is perfect, thanks!!

       
Laisvunas's avatar
Laisvunas
879 posts
17 years ago
Laisvunas's avatar Laisvunas

Hi eexperience,

Thanks for introducing new features into Browser Sniff plugin.

I will give a try and update the file in the first post in this thread.

       
Laisvunas's avatar
Laisvunas
879 posts
about 17 years ago
Laisvunas's avatar Laisvunas

Hi,

I have updated Browser Sniff plugin. You can download version 1.1.9 using the link in the first post in this thred.

The code of the new version incorporates additions of Timon (eexperience) which allow for {browser_name} and {browser_version} variables to be used both inside and outside conditionals.

Many thanks, Timon, for your help!

       
eexperience's avatar
eexperience
56 posts
about 17 years ago
eexperience's avatar eexperience

Hi Laisvunas, I’m glad I could be of help with my limited experience in coding.

Cheers, Timon

       
grantmx's avatar
grantmx
1,439 posts
about 17 years ago
grantmx's avatar grantmx

I’m lovin’ this plugin. It hard to target newer Safari/Webkit browsers with CSS “hacks” and this hits the spot! :cheese:

       
Laisvunas's avatar
Laisvunas
879 posts
about 17 years ago
Laisvunas's avatar Laisvunas

Hi,

I have released version 1.2 of Browser Sniff plugin.

In this version a serious bug - PHP error message saying that browser_version variable is undefined being displayed when outputted browser name is “other” - was fixed.

Most importantly this bug prevented using online validation services such as W3C validator. After analyzing user agent string of a validator plugin outputted browser name “other”, then because of the bug a PHP error message was being printed on the top of the web page, and this automatically resulted into markup of the web page being invalid.

Everyone who uses Browser Sniff plugin is recommended to upgrade.

       
grantmx's avatar
grantmx
1,439 posts
16 years ago
grantmx's avatar grantmx

I just noticed that since the release of FF3 when you do a specific sniff for saf (safari), it picks up FireFox 3 too. Any work around? I need to specifically target Safari.

This may be the fact that Firefox is somewhat built on the webkit platform.

Thanks!

       
grantmx's avatar
grantmx
1,439 posts
16 years ago
grantmx's avatar grantmx

The workaround in the mean time it to target the CSS3 selector :nth-child that no other browser supports, save Safari 3, which does.

/*Safari 3.x webkit-min hack can effect Opera 9.x too*/
@media screen and (-webkit-min-device-pixel-ratio:0) {
    
    /* :nth-child target only Konqueror 3.x (Safari 3.x) hat tip to  http://tanreisoftware.com/blog/?p=39#konq*/
    html:not(:nth-child(1)) add selector here{
        padding: blah, blah...
    }
}
       
Laisvunas's avatar
Laisvunas
879 posts
16 years ago
Laisvunas's avatar Laisvunas

Hi grantmx,

I just noticed that since the release of FF3 when you do a specific sniff for saf (safari), it picks up FireFox 3 too.

To test it I tried this code with Firefox 3.0.1 on Vista:

{exp:browser_sniff}
{if browser_name=="saf"}
Browser name: {browser_name}

Browser version: {browser_version}
{/if}
{/exp:browser_sniff}

and it worked as expected, that is there was no output.

       
1 2 3 4

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.