Page 1 of 1
Detect and Prompt iPhone Visitors
Posted: Sun Jan 16, 2011 5:43 pm
by Whatscookin
Hi I'm sorry if this is on the wrong board, I'm new to this but I like it allot.
I'am having trouble making it work. I place it in the head section, am I missing something?
Here is the code i use. found on
http://shaunmackey.com/articles/mobile/ ... -visitors/
<__script__ type="text/javascript">
function iPhoneAlert() {
if((navigator.userAgent.match(/iPhone/i))||(navigator.userAgent.
match(/iPod/i))){
var question = confirm(”Would you like to view the iPhone-optimized version of our site?”)
if (question){
window.location = “
http://lite.iphonemicrosites.com/home.html”;
}else{
window.location = “
http://iphonemicrosites.com/mainsite.html”;
}
}
}
</__script>
Re: Detect and Prompt iPhone Visitors
Posted: Mon Jan 17, 2011 12:24 am
by Dr.CSS
Anything that contains { } in it needs {literal} the code with { } in it {/literal}...
Re: Detect and Prompt iPhone Visitors
Posted: Mon Jan 17, 2011 11:31 am
by Whatscookin
Thank you for you quick reply.
I have tried puttin {literal} on the hole thing, one in the top and {/literal} in the bottom, did not work.
and just now I tried this
<__script__ type="text/javascript">
function iPhoneAlert() {literal}
if((navigator.userAgent.match(/iPhone/i))||(navigator.userAgent.
match(/iPod/i))){literal}
var question = confirm(”Would you like to view the iPhone-optimized version of our site?”)
if (question){literal}
window.location = “
http://lite.iphonemicrosites.com/home.html”;
{/literal}else{literal}
window.location = “
http://iphonemicrosites.com/mainsite.html”;
{/literal}
{/literal}
{/literal}
</__script>
And it just messed up my slider.
oh and thank you for the help.
Re: Detect and Prompt iPhone Visitors
Posted: Mon Jan 17, 2011 12:11 pm
by M@rtijn
No, just one literal tag around the code:
Code: Select all
<__script__ type="text/javascript">{literal}
function iPhoneAlert() {
if((navigator.userAgent.match(/iPhone/i))||(navigator.userAgent.
match(/iPod/i))){
var question = confirm(”Would you like to view the iPhone-optimized version of our site?”)
if (question){
window.location = “http://lite.iphonemicrosites.com/home.html”;
}else{
window.location = “http://iphonemicrosites.com/mainsite.html”;
}
}
}{/literal}
</__script>
If it's not working, it's probably the third-party code itself
Re: Detect and Prompt iPhone Visitors
Posted: Mon Jan 17, 2011 12:17 pm
by Whatscookin
M@rtijn wrote:If it's not working, it's probably the third-party code itself
Thank you for the help, it don't work so i quess its the code, but thanks anyways
Any of you know where I could read a little about this, tried google it, but thats a massive jungle.
Re: Detect and Prompt iPhone Visitors
Posted: Mon Jan 17, 2011 2:40 pm
by Whatscookin
So I got to work now.
Got a friend to look at it. the code I'm using is:
Code: Select all
<title>iphone</title>
<__script__ type="text/javascript">
function iPhoneAlert( )
{
if ( navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPod/i) )
{
var qes = confirm( "Would you like to view iPhone-optimized version of our site?" );
if ( qes )
window.location = "here goes your iphone site url.";
}
}
</__script>
And this:
</__body onload="iPhoneAlert( );">
Incase anybody would like it