3

I need to trigger event when user selects text in android touch device.In web browsers am able to trigger event by checking on each mouse up event whether window.getselection is null. Touch select text event not triggering.

document.addEventListener('touchend', function(event)
{
    if( window.getSelection){
        t = window.getSelection().toString();
        alert(t);
    }
});

I tried in touchend event.But when user selects text event not triggering.

tom joy
  • 391
  • 6
  • 22

1 Answers1

0

Why not try a jQuery solution using the .change() function? First you add the jQuery library immediately above your included JavaScript file declaration, then you've got jQuery capability in the document. Next read up on .change() and try something like:

  $('#touchend').change(function(){
      if(your condition){var $t = window.getSelection().toString();}
  });

or whatever JavaScript code you want in the function. jQuery is simply a JavaScript library, so you can use it freely with your JavaScript. It's a gamechanger!

BenMorel
  • 31,815
  • 47
  • 169
  • 296
  • I appreciate the edit, but was merely trying to add a link to direct the asker to jquery's .change() documentation. – The Sethness Oct 28 '13 at 22:57