Question

I am trying to display something specifically to iPhone users on a web page using conditional statements (like you would with IE).

<!--#if expr="(${HTTP_USER_AGENT} = /iPhone/)"-->
Hello
<!--#endif -->  

This doesn't seem to be hiding itself from non-iPhone users. Anybody have any suggestions?

Was it helpful?

Solution 2

OK, i ended up solving this via Cody Gray's advice.

CSS:

<!--#if expr="(${HTTP_USER_AGENT} = /iPhone/)"-->
<style type="text/css">
<!--
.iPhone {visibility:visible;}
-->
</style>
<!--#else -->
<style type="text/css">
<!--
.iPhone {visibility:hidden}
-->
</style>
<!--#endif -->

HTML

<div class="iPhone">
Hi
</div>

*Edit

I ended up doing this in .net and a placeholder:

Front end:

<asp:PlaceHolder ID="myPlaceHolder" runat="server"> 
hi
</asp:PlaceHolder> 

Code behind:

 String userAgent;
        userAgent = Request.UserAgent;
        if (userAgent.IndexOf("iphone") > -1)
        {
            myPlaceHolder.Visible = true;
        }
        else
        {
            myPlaceHolder.Visible = false;

        }
    }

OTHER TIPS

Use javascript or server-side processing.

.js:

if (navigator.userAgent.indexOf('iPhone') > -1)
    document.getElementById('iphoneMessage').style.visibility = 'visible';  
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top