homepage Welcome to WebmasterWorld Guest from 54.167.179.48
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Disable javascript for ipad
help with code please
xert



 
Msg#: 4407009 posted 5:04 pm on Jan 15, 2012 (gmt 0)

Hi,

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">
Shadowbox.init();
</script>

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.

Chris

 

lucy24

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



 
Msg#: 4407009 posted 9:08 pm on Jan 15, 2012 (gmt 0)

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.

xert



 
Msg#: 4407009 posted 9:15 am on Jan 16, 2012 (gmt 0)

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

Chris

lucy24

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



 
Msg#: 4407009 posted 10:11 am on Jan 16, 2012 (gmt 0)

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}

xert



 
Msg#: 4407009 posted 11:18 am on Jan 16, 2012 (gmt 0)

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 ?

rocknbil

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



 
Msg#: 4407009 posted 9:26 pm on Jan 16, 2012 (gmt 0)

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


<script type="text/javascript">
Q.isMobile=false;
J=navigator.userAgent.toLowerCase();
if(J.indexOf("iphone")>-1||J.indexOf("ipad")>-1||J.indexOf("ipod")>-1||J.indexOf("android")>-1){
Q.isMobile=true;
}
if ((Q.isMobile==false)) { Shadowbox.init(); }
</script>

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.

xert



 
Msg#: 4407009 posted 12:11 am on Jan 17, 2012 (gmt 0)

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,

Chris

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved