In my Android app I'm attaching a handler for the Javascript onselectionchange like this:
$(document).on('selectionchange',function(ev){
alert('Text has been selected');
});
This is supposed to be fired when the user selects something (like text) or the selection changes, however it is fired on tap. Does anyone know the reason of this behavior? (Something like this is working in iOS)
"onselectionchange" event is not a cross-browser feature.
AFAIK, it's only Trident (iexplore) and recent versions of webkit (and hence webview) that support text selection events.
That being said, could it be that the version of webkit present on the iOS you tested is more recent than your Android's version?
Also consider that though they both render with webkit, they use totally different javascript engines, hence potentially different behaviour.
Related
I made use of the https://github.com/jaridmargolin/formatter.js library in my project and discovered it is not working properly on mobile devices.
My research showed that this is due to it's use of keypress which is evil and should not be used. So I decided to modify it and use "beforeinput" whenever available. And here lies the problem, how do I detect whether it is available?
I tried this methode: https://stackoverflow.com/a/2877424/13987708
But it doesn't work.
My Internet search only showed me a bunch of different veriations of the same methode when checking for detecting supported events in a browser. And I can see that this method most of the times works. it even works for the "input" event, but unfortunatly not for the "beforeinput" event.
I would love to find a way that does not rely on the user agent, as that is, so I'm told, very unrelyable.
// EDIT
Well, I did research the issue, I even say so in my question :duh:...
The situation is that "keypress" is deprecated and should not be used anymore, in fact in Chrome for Android it doesn't even fire anymore.
The above mentioned plugin to format user input relies on the methode, though.
So I went ahead and replaced it with the "keyup" methode, which indeed fires in Chrome for Android, but only gives a keyCode of 229, so it doesn't work either.
I dug a bit deeper into this whole keyboard events and found that modern browsers support the "beforeinput" event (https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/beforeinput_event).
Which is awesome, it gives you so much mor information about the interaction between the user and your input.
So I adapted the formatter to use the "beforeinput" event instead of "keypress", but my project has to support IE, which does not support "beforeinput".
That's why I need a way to detect if the browser supports this event, and use either the "keypress" or the "beforeinput" depending on the capabilities of the users browser.
And I am aware that a browser might support functionality which the user won't use, but it's not relevant for this use case, I just need to know if the browser will fire the "beforeinput" event or not.
Building a site with jQuery and jGestures and have noticed some devices such as iPads won't respond to the on 'click' event instead they respond to 'tapone'.
I replaced all instances of 'click' with 'tapone' and after testing in various browsers I have noticed no issues. Browsers include the latest versions of IE, Firefox, Chrome for Windows and Safari on Ipad 4.
What are the drawbacks to replacing all instances of: on('click', .... with: on('tapone', ...
Will this cause issues with any desktop browsers?
click is the native browser event.
tapone is a custom event triggered by the jGestures library to capture a one-finger tap. (It also has taptwo etc for multi-touch taps.)
If you are using the library, use its events. Seems like it normalizes to click on non-touch browsers which is why you don't see any issues.
From the documentation:
On every native touchstart, touchend, gesturestart and gestureend-event, jgestures triggers a corresponding custom event (jGestures.touchstart,jGestures.touchend,jGestures.gesturestart and jGestures.gestureend) on the event-element.
I have a button on my page called "Print". clicking on which will trigger a jQuery function.
I need to call the same jQuery function when user hits Alt+f+p or ctrl+p
How do I do that?
I tried to do that with matchMedia but no luck
if (window.matchMedia('print').matches) {
alert("print using browser");
}
There is not a standard way to do that as far as I know.
IE and FF offer own function calls,
In IE there are the nonstandard window.onBeforePrint() and window.onAfterPrint() event listeners. There isn't a non-IE way to do it that I know of, however.
Firefox 6 now supports beforeprint and afterprint
https://developer.mozilla.org/en/Printing#Detecting_print_requests
A universally working solution might be to just listen for CMD+P.
I am programming an application by using Windows ActiveX web control which uses html buttons for input interaction. On differing versions of Windows XP this control may be IE6 or IE7. On Winodws 7 x64 with IE11 installed it is still IE7. I do not know what version is available on Windows 8.
Operating within these limitations (IE6/IE7), is there a javascript fast click solution for these browsers?
I found that handling both the .click and .dblclick events with jQuery will simulate fast click for events which trigger on "mouse up". However, I would prefer for this particular application for the event to fire on mouse-down instead of mouse-up. I can get half of it with .onmousedown, but .dblclick activates on mouse up which makes interaction jumpy on double click.
I tried various fast click implementations on the internet and was unable to find an adequate solution. I am able to use versions of jQuery prior to version 2.0.
If you feel comfortable running an executable, I've written a simple demo application which accepts a single command-line parameter for passing the target web page url. This demo will utilize your operating system's IE ActiveX control for testing purposes.
You can pass a file path as the url with this program. However, it was only tested with the IE7 ActiveX control. I don't know if a file path will work for IE6, but I believe it should.
http://codespunk.com/files/upload/html_test.zip
If someone out there is using Windows 8 and 8.1, I would be interested to know what the result is for "http://whatbrowser.org" so we can see what version of IE the control is using.
I'm searching for a method how to detect if the device is handheld.
Currently I'm using http://detectmobilebrowsers.com/ but I don't like the whole userAgent string detection method.
I came across this script (http://kangax.github.com/iseventsupported/) that tests the support of events in browser and it made me thinking what if I'll just test "mouseover" or "touchstart" event or both to deside if the device is handheld.
In my project I need to detect if the input password supports showing the last typed character like in iPhone or Android.
So what do you think, is the event detection approach good or is there any better solution?
UPDATE:
I decided to use (detect) the support of orientationchange event in browser.