Detect and Prompt iPhone Visitors

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
Whatscookin
New Member
New Member
Posts: 4
Joined: Sun Jan 16, 2011 5:32 pm

Detect and Prompt iPhone Visitors

Post 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>
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am
Location: Arizona

Re: Detect and Prompt iPhone Visitors

Post by Dr.CSS »

Anything that contains { } in it needs {literal} the code with { } in it {/literal}...
Whatscookin
New Member
New Member
Posts: 4
Joined: Sun Jan 16, 2011 5:32 pm

Re: Detect and Prompt iPhone Visitors

Post 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.
User avatar
M@rtijn
Power Poster
Power Poster
Posts: 706
Joined: Sat Nov 14, 2009 4:54 pm
Location: the Netherlands

Re: Detect and Prompt iPhone Visitors

Post 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
Make your community a better place!
Whatscookin
New Member
New Member
Posts: 4
Joined: Sun Jan 16, 2011 5:32 pm

Re: Detect and Prompt iPhone Visitors

Post 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.
Whatscookin
New Member
New Member
Posts: 4
Joined: Sun Jan 16, 2011 5:32 pm

Re: Detect and Prompt iPhone Visitors

Post 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
Post Reply

Return to “Developers Discussion”