Solved

java script if clause

Posted on 2012-04-08
6
248 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
  • 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now