Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

Disable javascript for ipad

help with code please



5:04 pm on Jan 15, 2012 (gmt 0)

5+ Year Member


I am using an image viewer script which works fine on most browsers, but not on ipad, iphone and android browsers.

I understand that the user agent string can be used to recognise these browsers, but unsure how to implement a code to disable the viewer when the user is on the aforementioned browsers.

As well as the browser javascript, the webpages have the following code to run the viewer :

<script type="text/javascript">

Can anyone suggest a code to add to either the viewer script or the init() code above to do as I require ?

Many thanks in advance to all.



9:08 pm on Jan 15, 2012 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

Yup. Look for the words "iPhone, iPad, android"-- and I assume also iPod-- in the User Agent. Even a case-sensitive "iP" will pick up most of 'em ;) Not the javascript Browser function, which divides the entire world into MSIE and Netscape.* The full user-agent match using a simple Regular Expression. Don't have the exact code in my head, but I've done it myself and I only speak about ten words of javascript so I know it isn't very hard. Something, slash, something else, slash.

It's a simple "if" construction. First send the user to the function that looks at the user agent. And then if it doesn't match anything on your list-- might throw "mobile" into the mix too-- send them along to the existing Shadowbox function.

You might also think about simple alternatives for the increasing number of people who do use mobiles. Don't know about the smaller devices, but the iPad browser handles javascript popups by making a new tab, exactly as if you were opening a regular tab or window.

* And possibly Opera, which refuses to be diviz.


9:15 am on Jan 16, 2012 (gmt 0)

5+ Year Member

Hi Lucy24,

Many thanks for your reply. I have a piece of code which I believe will detect the browsers which I wish to disable the viewer script for :

var J=navigator.userAgent.toLowerCase()if(J.indexOf("iphone")>-1||J.indexOf("ipad")>-1||J.indexOf("ipod")>-1||J.indexOf("android")>-1){Q.isMobile=true};

What I need help with is how to use the Q.isMoblile variable to stop the script. Although able to build websites, unfortunately I have no knowledge of coding javascript !

Kind regards



10:11 am on Jan 16, 2012 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

how to use the Q.isMobile variable to stop the script.

I'd do it the other way around. Check for UA, and if Q-thingie is false, then start the script. Conceptually it may be easier if you turn the variable around too, like:

check userAgent
if userAgent is not "mobile" then goodToGo = true
if goodToGo then...
{and now go to the script}


11:18 am on Jan 16, 2012 (gmt 0)

5+ Year Member

Thank you for your reply. Although I understand your method, I am not learned to build the actual code to do this.

Can you or anyone offer the code to be used ?


9:26 pm on Jan 16, 2012 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member

You know that's also killing it on the 'droid, right?

<script type="text/javascript">
if ((Q.isMobile==false)) { Shadowbox.init(); }

Though, I'll say, a better path is to find out what's going wrong on the 'pad and fix it. :-) The pad is really just Safari in a skinny box, the learning curve lives in the variable viewport of the 'pad.


12:11 am on Jan 17, 2012 (gmt 0)

5+ Year Member

Thanks rocknbil - really appreciate your time with the code. Works a treat.
Much has been documented about shadowbox's inability to handle the ipad browser - killing the script is the easiest way to keep users until a fix has been created for the viewer javascript.

Best regards,


Featured Threads

Hot Threads This Week

Hot Threads This Month