homepage Welcome to WebmasterWorld Guest from 50.17.176.149
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe and Support WebmasterWorld
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Stop javascript function on mobile devices
chrisv1963




msg:4572634
 10:00 am on May 10, 2013 (gmt 0)

I would like to use the sticky footer bar [dynamicdrive.com...] on my website.

It works on all browsers, but looks awful on an iPad.
How can I detect iPad, iPod and Iphone and automatically disable expstickybar.js on those devices?

 

lucy24




msg:4572807
 6:48 pm on May 10, 2013 (gmt 0)

How can I detect

Lots of ways. But if you're already using a process that requires js, may as well put the UA detection into the same function. If the user doesn't have js, no point in even checking.

Now, what about other mobiles? You'd want to screen out androids and so on too wouldn't you?

Alternative approach: Can you code it to detect mouse-hovers that are not clicks? This alone might make the mobiles problem go away. In a browser, a click is always preceded by a hover. In a tablet, there's only one mouse event. (Talking here about vanilla html, not custom-written apps.)

chrisv1963




msg:4573025
 10:41 am on May 11, 2013 (gmt 0)

I thought that fixed position was not supported by iPads, iPods and iPhones only. But, yes, maybe it is better to exclude all mobile devices.

The problem is that I am a javascript dummy and don't know how to write the code to detect mobile devices and disable a certain script.

lucy24




msg:4573153
 7:36 pm on May 11, 2013 (gmt 0)

Oh, oops, you're thinking about position. I thought you were concerned about the opened-out navigation bar taking up too much real estate. So I was thinking only of disabling the popup element.

I don't have the exact UA-detection formula at my fingertips, but it's quite basic; you can find it anywhere, down to and including w3schools.

It's not really a matter of "disabling" a script. You'd be adding one nest to the structure:

if (action is mouse-hover)
THEN
if (user-agent is on this short list-- or is NOT on this other short list, whichever is convenient and appropriate)
THEN
carry on with the function.

Menu activation is something that typically happens more than once on a page, let alone more than once on a site, so you probably don't want to check the UA every time. Check once and set either a global variable or a cookie, depending on how long you want it to last.

:: detour here to do what I should have done in the first place: check the actual link with an iPad ::

There's a preliminary hiccup where the navigation footer expands and drifts upward as I scroll, but as soon as I "click" it collapses and stays at the bottom. There may be a glitch in the way your source site detects user-agents. But, hey, nothing wrong with writing code that's better than the original ;)

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.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved