1

I want that when I surf with my iPhone to my site that my iPhone get another text than when I surf with my Mac

<script type="text/javascript">
if ((navigator.userAgent.match(/iPhone/i))
       || (navigator.userAgent.match(/iPod/i))
       || (navigator.userAgent.match(/iPad/i))) {
    document.write("you are surfing with an iPhone");
} else {
    document.write("you are not surfing with an iPhone")
}
</script>

It won't work. Is there anyone who can help me?

Ps. sorry for my bad English, I'm from Belgium, Flanders

1 Answer 1

2
if (navigator.userAgent.match(/iPhone/i)
    || navigator.userAgent.match(/iPod/i)
    || navigator.userAgent.match(/iPad/i))
{
     alert("It's an iPhone or iPod");
}

Works a treat, I just tested it on my iPhone using jsFiddle. ​

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your fast answer :)
ahhhh :] elegant, lovely.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.