?
Solved

Conditional statement

Posted on 2013-05-11
20
Medium Priority
?
410 Views
Last Modified: 2013-05-12
There is a page on my website which does not work under iPad Safari, but it works well on most laptops and desktops.  I have an alternate version of that page, which does work under iPad.  How can I serve the alternate version for visitors using the iPad, and maintain the original version for the remainder of browsers?
0
Comment
Question by:ddantes
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 7
  • 4
20 Comments
 
LVL 82

Expert Comment

by:David Johnson, CD, MVP
ID: 39158836
You need to use the useragent and then redirect depending upon the user agent.
 
$useragent = $_SERVER['HTTP_USER_AGENT'];
//Google Chrome example
if( strpos($useragent,"Chrome") ) {
header("Location: http://chrome.mydomain.com/");
}

or use the useragent to select specific css

The exact implentation will depend upon the language and server involved.
0
 

Author Comment

by:ddantes
ID: 39158883
Thank you for your comment.  I'm not experienced enough to be able to implement your instructions, so please try to provide more specific detail.  

Do I place this statement in a page which then redirects the browser to another target?

If the user's browser is iPad Safari, I would like their browser to load www.mauitradewinds.com/view3.htm   Otherwise, I would like their browser to load www.mauitradewinds.com/view.htm
0
 
LVL 82

Expert Comment

by:David Johnson, CD, MVP
ID: 39158976
http://developer.apple.com/library/IOs/#documentation/AppleApplications/Reference/SafariWebContent/OptimizingforSafarioniPhone/OptimizingforSafarioniPhone.html

Your server is apache 2.2
http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html

in your httpd.conf add the following and restart the server

<IfModule mod_rewrite.c>  
RewriteEngine on  
RewriteCond  %{HTTP_USER_AGENT}  ^Ipad
RewriteRule  ^/$                 /view3.htm  [L]
RewriteRule  ^/$                 /view.htm [L]
</IfModule>
0
RHCE - Red Hat OpenStack Prep Course

This course will provide in-depth training so that students who currently hold the EX200 & EX210 certifications can sit for the EX310 exam. Students will learn how to deploy & manage a full Red Hat environment with Ceph block storage, & integrate Ceph into other OpenStack service

 

Author Comment

by:ddantes
ID: 39159001
Thank you.  I believe your instructions rely on a server-side code.  Sorry for not mentioning this, but I'm looking for a client-side solution, such as a common page with html which uses a conditional statement, or feature detection, to direct the user's browser to one or another version of the view.htm page, depending on whether or not it is iPad Safari.  Can you provide that code?
0
 
LVL 82

Expert Comment

by:David Johnson, CD, MVP
ID: 39159022
are you using php? straight html? aspx?
0
 

Author Comment

by:ddantes
ID: 39159040
I can use html and php.
0
 
LVL 82

Assisted Solution

by:David Johnson, CD, MVP
David Johnson, CD, MVP earned 800 total points
ID: 39159063
<script type="text/javascript"> // <![CDATA[
if (navigator.userAgent.indexOf('iPad') != -1) ) {
    document.location = "www.mauitradewinds.com/view3.htm  ";
} // ]]></script>
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 39159070
window.location.replace("http://www.mauitradewinds.com/view3.htm");

would be a lot better than breaking the back button and using the deprecated and possibly read-only document.location
0
 

Author Comment

by:ddantes
ID: 39159082
Safari user agent is set to iPadThank you both for your instructions.  I added the specified code to the <HEAD> section of view.htm, then opened that page with the Safari browser, having set the useragent to "iPad" (please see screenshot).  However, the page appearing in the browser was still view.htm, not view3.htm.  I tried both "document.location" and "window.location.replace".  What am I overlooking?
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 39159102
try this
<script>
if (navigator.userAgent.indexOf('iPad') != -1)  {
    window.location.replace("http://www.mauitradewinds.com/view3.htm");
}
else alert(navigator.userAgent);
</script>

Open in new window

and see if there are any mentioning of iPad (case sensitive) in the useragent
0
 

Author Comment

by:ddantes
ID: 39159107
Thank you.  However, view.htm continues to load when I access it with Safari and the useragent set for iPad.  I'm not sure what is meant by a "mentioning of iPad in the useragent".

Just to be clear, I've inserted this code into view.htm, expecting it to redirect the browser to view3.htm if the useragent=iPad.  Do you happen to have an iPad?  If so, I could upload the file to my server, instead of testing it locally.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 39159130
Yes I do have an ipad. Please do upload
0
 

Author Comment

by:ddantes
ID: 39159135
Great!  I uploaded the view.htm with the recommended script.  It's at http://mauitradewinds.com/view.htm   I'd be curious to know if it scrolls OK on your iPad.  But the main question is, why doesn't it redirect the browser to view3.htm?
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 39159155
I see indexOf(\'iPad\')

Which must be
indexOf('iPad')
So something in your upload procedure changed the quotes.
Try double quotes

View3 scrolls ok in ipad
0
 

Author Comment

by:ddantes
ID: 39159157
That is difficult to understand.  I just checked the source under Internet Explorer and under Safari for Windows, and it says
indexOf('iPad')  

What now?
0
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 1200 total points
ID: 39159173
Ah, I see it in the console

You have a ) too many.

if (navigator.userAgent.indexOf('iPad') != -1) ) {

should be

if (navigator.userAgent.indexOf('iPad') != -1)  {
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 39159177
All that said perhaps you should just change to

http://jquery.vostrel.cz/reel

which supports the newer and mobile browsers
0
 

Author Comment

by:ddantes
ID: 39159211
Good eye!  It works now.  I'll look at the other plug-in as well.   One last question:  did view.htm scroll under your iPad, before the redirect code was fixed just now?   If you didn't get a chance to check that before, that page is now at http://mauitradewinds.com/viewx.htm  Thank you for all your help.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 39159551
On viewx the scrolling is VERY slow but that is also the case on view3
0
 

Author Comment

by:ddantes
ID: 39159759
Thank you for checking.   I've posted a new question at www.experts-exchange.com/Software/Internet_Email/Web_Browsers/Q_28125504.html#a39159770  asking how to implement the jquery.reel plugin which you recommended as an alternative to the existing javascript.  If you would like to comment under the new question?
0

Featured Post

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Do you come here a lot? Are you lazy like me and don't want to go through the "trouble" of having to click your Dock's Safari icon and then having to click your Experts Exchange Favorites bookmark to get here? Well then this article is for you.
This article offers some helpful and general tips for safe browsing and online shopping. It offers simple and manageable procedures that help to ensure the safety of one's personal information and the security of any devices.
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question