Solved

java script if clause

Posted on 2012-04-08
6
253 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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
LVL 23

Accepted Solution

by:
basicinstinct earned 300 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

739 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