Plugin

Developer
Supported

Browser Sniff

ExpressionEngine 2

Back to this add-on's main page
View Other Add-ons From Laisvunas

     

You must be logged in to post.

Not working on index?

Support Request

advg
advg

I set up the following code on our homepage:

{exp:browser_sniff}
  {if browser_sniff_is_mobile 
== "yes"}
   {redirect
="home/m_index"}
  {
/if}
 {
/exp:browser_sniff} 

However when going to this page via the root domain URL, the redirect does not trigger. It works only when visiting /home/index (the template group location of the homepage).

Could there be a reason for browser_sniff not working in this scenario?

Laisvunas
# 1
Developer
Laisvunas

Hi,

Redirect might not be triggered for many reasons. Please, check if conditional is working correctly by using this code:

{exp:browser_sniff}
  {if browser_sniff_is_mobile 
== "yes"}
  
<bIs mobile!</b>
  
{/if}
 {
/exp:browser_sniff} 

If conditional is working correctly, then you always can execute redirect via either PHP or Javascript.
In case ExpressionEngine’s native {redirect} tag does not work you can use plugin such as HS Redirect which supports both PHP and JS methods.

advg
# 2
advg

Sorry for getting back to this a year (!) later. I stopped developing my site for a while, but now I’m back.

It seems this is not related to the redirect. I used browsersniff to just display some text similar to how you suggested, and it’s always displaying “It’s something else!” when viewing on a Mac. But only in the root of my domain, not when viewing the template in its actual location.

{exp:browser_sniff}
    {if browser_sniff_platform_shortname 
== "Mac"}
It
's a Mac!
    {if:else}
It'
s something else!
    
{/if}
   {
/exp:browser_sniff} 
Laisvunas
# 3
Developer
Laisvunas

Hi,

I tried to replicate the issue, but unsuccessfully.

On my server your code outputs correctly “It’s a Mac!” when using Safari browser on OS X, both in the site root and in other templates.

The issue happens when you use Safari or some other browser? Does the issue happens in several browsers?