Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

java script if clause

Posted on 2012-04-08
6
Medium Priority
?
258 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

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…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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)
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

636 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