dimanche 26 juin 2016

Special behavior for simple browsers that doesn't depend on sniffing or js support


I wrote some js that does an elevator-like scroll to an anchor when you click on a link above it, using setInterval(). It also sets up a few sounds (rumble, ding.) Works great on PC browsers, but I'd never get it to work on mobile. For that, I just want it to link to the anchor.

Some mobiles don't do js, so detecting browser w/ js won't work, and I want to avoid using navigator.userAgent.

So I'm doing this:

HTML:
<a id=noop_me onClick="javascript:elevator_button();"    href="#anchor">Elevator</a>

JS:
elevator_button() {
// set up the fancy scrolling, etc.

// Before returning, nullify the href=
document.getElementById ("noop_me").href = "javascript:void(0)";
}

non-js browsers ignore the js call, and simply follow the unmolested href link. I put the nullifier here and not in onLoad, so there'd be just one bifurcation point. This assumes that the js is always executed before the href is looked at.

So far it works nicely on my Pop Astro (& PCs.) Does anyone see problems with this? Such as w/ other mobiles? Or is it too good to be true?


Aucun commentaire:

Enregistrer un commentaire