?
Solved

java script if clause

Posted on 2012-04-08
6
Medium Priority
?
255 Views
Last Modified: 2012-06-27
I have line of information I would like to leave out if the site visitor is looking at a site via an ipad. Is there any java script that will allow me to do this:

if !ipad "some string"

Thanks,
N
0
Comment
Question by:Neil_Bradley
[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
  • 4
  • 2
6 Comments
 
LVL 23

Expert Comment

by:basicinstinct
ID: 37822008
if(!(/iPad/.test(navigator.userAgent)))
{
//do stuff
}

Open in new window

0
 
LVL 23

Expert Comment

by:basicinstinct
ID: 37822015
to make it slightly more robust you could make the regex case insensitive:

/iPad/i instead of /iPad/
0
 
LVL 5

Author Comment

by:Neil_Bradley
ID: 37822051
Thanks basicinstinct,
if I wanted to echo an alternate style sheet using your code how would I do this?
IE
if(!(/iPad/.test(navigator.userAgent)))
{
<link rel="stylesheet" href="css/style.css">
}
Cheers,
N
0
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
LVL 23

Accepted Solution

by:
basicinstinct earned 1200 total points
ID: 37822129
well normally that would be done on the server side,
but for argument's sake if you want to do it on the client side then you could do something like this:

(function(){
if(!(/iPad/i.test(navigator.userAgent)))
{
    var newCss = document.createElement("link");
    newCss.setAttribute("rel", "stylesheet");
    newCss.setAttribute("href", "css/style.css");
    document.body.appendChild(newCss);
}
})();¿
0
 
LVL 5

Author Closing Comment

by:Neil_Bradley
ID: 37822157
That's perfect and extremely thorough, thank you.
I am guessing that an alternate method code be:
 if(/iPad/.test(navigator.userAgent))
{
document.write("<link rel=\"stylesheet\" href=\"css/device.css\">");
}
        </script>

Cheers,
N
0
 
LVL 23

Expert Comment

by:basicinstinct
ID: 37831440
yes but i NEVER use document.write, it makes me do this

>:(
0

Featured Post

7 Extremely Useful Linux Commands for Beginners

Just getting started with Linux? Here's a quick start guide that has 7 commands that we believe will come in handy.

Question has a verified solution.

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

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

762 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