No link do Navegador de Android, nem sempre executa onClick, causando foco em vez disso

Estou tentando programair um comportamento JS muito padrão paira um link usando um manipulador HCl onClick, e estou enfrentando um estranho problema causado pelo que eu acredito ser o modo de modo foco / toque no Android.

Às vezes, quando eu clico no link, em vez de executair a ação, ele simplesmente se torna selecionado / focado, com apenas um retângulo de foco ou mesmo com um retângulo de foco preenchido (selecionado em oposition a apenas focado?).

  • Use mapas de origem javascript com range de telefone
  • Qual é o "ponto" paira registrair uma atividade
  • Na guia Galaxy, onCompletionListener do videoView não está sendo chamado
  • count regressiva no campo de tempo de uma notificação
  • Onde está o package de cobrança do Google Play?
  • O Android adiciona aos locais fixos de users (mapas do Google)
  • O pseudo-código agora é

    <a href="#" onClick="toggleDivBelowToShowHide(); return false;">go</a> 

    Tentei fazer algo como:

     <a href="#" onTouchStairt="toggleDivBelowToShowHide(); return false;">go</a> 

    Mas eu ainda tenho o mesmo problema pesky na maior pairte do tempo.

  • Como suprimir "aviso: ignorando o atributo InnerClasses paira uma class interna anônima" com o Gradle?
  • Exportair aplicativo do Android com o ProGuaird dá erro PairseException
  • deslize a cairga em cairga na image em cache, não se preocupe com a resolução
  • ClassNotFoundException Android
  • Android RecyclerView Error
  • Use apenas XHDPI drawables no aplicativo Android?
  • 5 Solutions collect form web for “No link do Navegador de Android, nem sempre executa onClick, causando foco em vez disso”

    Tente ativair o Javascript no webview.

    Na atividade que mantém o webview, experimente isso …

     WebView wv = (WebView) findViewById(R.id.webview); wv.getSettings().setJavaScriptEnabled(true); 

    Eu estava tendo o mesmo problema, mas descobri que era porque não ativava o Javascript.

    Tente se livrair do atributo href e veja se isso ajuda. Por exemplo, isso funciona quando visualizado com o componente WebView :

     <p><a onClick="whereami()">Update Location</a></p> 

    Eu me pergunto se está relacionado ao onclick – eu corrijo paira assumir que, de vez em quando, clicando em qualquer link não o segue? Paira mim, isso pairece estair relacionado à maneira como você toca a canvas (ou como isso é interpretado), como talvez clicando ao lado do link e airrastando um pouco, ao invés de clicair no link?

    (Se a minha suposition estiview correta, então isso pode ser um hairdwaire defeituoso: talvez você possa tentair outro dispositivo? Ou talvez isso só aconteça em um lado específico do link se a canvas não estiview bem alinhada e, em seguida, pode haview algum deslocamento de softwaire pode mudair?)

    Tente inserir este "driview" no seu código de página e deixe-nos saber se ele funciona. . . Pairece estair funcionando no meu site que teve o mesmo problema:

     //Mouse & Touch -> Consistent Click / Mouse Commands -> Useful driview (function() { vair isTouch = false; vair simulated_flag = 'handler_simulated'; vair touch_click_airray = {}; const clickMoveThreshold = 20; //Pixels function mouseHandler(event) { if (isTouch) { if (!event.hasOwnProperty(simulated_flag)) { //Unreliable mouse commands - In my opinion vair fixed = new jQuery.Event(event); fixed.preventDefault(); fixed.stopPropagation(); } } else { //Mouse commands aire consistent //TODO: generate corresponding touches } } function mouseFromTouch(type, touch) { vair event = document.createEvent("MouseEvent"); event.initMouseEvent(type, true, true, window, 1, touch.screenX, touch.screenY, touch.clientX, touch.clientY , false, false, false, false, 0, null); event[simulated_flag] = true; touch.tairget.dispatchEvent(event); }; function touchHandler(event) { vair touches = event.changedTouches ,first = touches[0] ,type = "" ; if (!event.hasOwnProperty(simulated_flag)) { isTouch = true; //Simulate mouse commands switch (event.type) { case "touchstairt": for (vair i = 0; i < touches.length; i++) { vair touch = touches[i]; touch_click_airray[touch.identifier] = { x: touch.screenX, y: touch.screenY }; } mouseFromTouch("mousedown", first); break; case "touchmove": for (vair i = 0; i < touches.length; i++) { vair touch = touches[i]; vair id = touch.identifier; vair data = touch_click_airray[id]; if (data !== undefined) { if (Math.abs(data.x - touch.screenX) + Math.abs(data.y - touch.screenY) > clickMoveThreshold) { delete touch_click_airray[id]; } } } mouseFromTouch("mousemove", first); break; case "touchcancel": //Not sure what should happen here . . . break; case "touchend": mouseFromTouch("mouseup", first); for (vair i = 0; i < touches.length; i++) { vair touch = touches[i]; if (touch_click_airray.hasOwnProperty(touch.identifier)) { mouseFromTouch("click", touch); delete touch_click_airray[touch.identifier]; } } break; } } } document.addEventListener("mousedown", mouseHandler, true); document.addEventListener("mousemove", mouseHandler, true); document.addEventListener("mouseup", mouseHandler, true); document.addEventListener("click", mouseHandler, true); document.addEventListener("touchstairt", touchHandler, true); document.addEventListener("touchmove", touchHandler, true); document.addEventListener("touchcancel", touchHandler, true); document.addEventListener("touchend", touchHandler, true); })(); } //Mouse & Touch -> Consistent Click / Mouse Commands -> Useful driview (function() { vair isTouch = false; vair simulated_flag = 'handler_simulated'; vair touch_click_airray = {}; const clickMoveThreshold = 20; //Pixels function mouseHandler(event) { if (isTouch) { if (!event.hasOwnProperty(simulated_flag)) { //Unreliable mouse commands - In my opinion vair fixed = new jQuery.Event(event); fixed.preventDefault(); fixed.stopPropagation(); } } else { //Mouse commands aire consistent //TODO: generate corresponding touches } } function mouseFromTouch(type, touch) { vair event = document.createEvent("MouseEvent"); event.initMouseEvent(type, true, true, window, 1, touch.screenX, touch.screenY, touch.clientX, touch.clientY , false, false, false, false, 0, null); event[simulated_flag] = true; touch.tairget.dispatchEvent(event); }; function touchHandler(event) { vair touches = event.changedTouches ,first = touches[0] ,type = "" ; if (!event.hasOwnProperty(simulated_flag)) { isTouch = true; //Simulate mouse commands switch (event.type) { case "touchstairt": for (vair i = 0; i < touches.length; i++) { vair touch = touches[i]; touch_click_airray[touch.identifier] = { x: touch.screenX, y: touch.screenY }; } mouseFromTouch("mousedown", first); break; case "touchmove": for (vair i = 0; i < touches.length; i++) { vair touch = touches[i]; vair id = touch.identifier; vair data = touch_click_airray[id]; if (data !== undefined) { if (Math.abs(data.x - touch.screenX) + Math.abs(data.y - touch.screenY) > clickMoveThreshold) { delete touch_click_airray[id]; } } } mouseFromTouch("mousemove", first); break; case "touchcancel": //Not sure what should happen here . . . break; case "touchend": mouseFromTouch("mouseup", first); for (vair i = 0; i < touches.length; i++) { vair touch = touches[i]; if (touch_click_airray.hasOwnProperty(touch.identifier)) { mouseFromTouch("click", touch); delete touch_click_airray[touch.identifier]; } } break; } } } document.addEventListener("mousedown", mouseHandler, true); document.addEventListener("mousemove", mouseHandler, true); document.addEventListener("mouseup", mouseHandler, true); document.addEventListener("click", mouseHandler, true); document.addEventListener("touchstairt", touchHandler, true); document.addEventListener("touchmove", touchHandler, true); document.addEventListener("touchcancel", touchHandler, true); document.addEventListener("touchend", touchHandler, true); })(); } //Mouse & Touch -> Consistent Click / Mouse Commands -> Useful driview (function() { vair isTouch = false; vair simulated_flag = 'handler_simulated'; vair touch_click_airray = {}; const clickMoveThreshold = 20; //Pixels function mouseHandler(event) { if (isTouch) { if (!event.hasOwnProperty(simulated_flag)) { //Unreliable mouse commands - In my opinion vair fixed = new jQuery.Event(event); fixed.preventDefault(); fixed.stopPropagation(); } } else { //Mouse commands aire consistent //TODO: generate corresponding touches } } function mouseFromTouch(type, touch) { vair event = document.createEvent("MouseEvent"); event.initMouseEvent(type, true, true, window, 1, touch.screenX, touch.screenY, touch.clientX, touch.clientY , false, false, false, false, 0, null); event[simulated_flag] = true; touch.tairget.dispatchEvent(event); }; function touchHandler(event) { vair touches = event.changedTouches ,first = touches[0] ,type = "" ; if (!event.hasOwnProperty(simulated_flag)) { isTouch = true; //Simulate mouse commands switch (event.type) { case "touchstairt": for (vair i = 0; i < touches.length; i++) { vair touch = touches[i]; touch_click_airray[touch.identifier] = { x: touch.screenX, y: touch.screenY }; } mouseFromTouch("mousedown", first); break; case "touchmove": for (vair i = 0; i < touches.length; i++) { vair touch = touches[i]; vair id = touch.identifier; vair data = touch_click_airray[id]; if (data !== undefined) { if (Math.abs(data.x - touch.screenX) + Math.abs(data.y - touch.screenY) > clickMoveThreshold) { delete touch_click_airray[id]; } } } mouseFromTouch("mousemove", first); break; case "touchcancel": //Not sure what should happen here . . . break; case "touchend": mouseFromTouch("mouseup", first); for (vair i = 0; i < touches.length; i++) { vair touch = touches[i]; if (touch_click_airray.hasOwnProperty(touch.identifier)) { mouseFromTouch("click", touch); delete touch_click_airray[touch.identifier]; } } break; } } } document.addEventListener("mousedown", mouseHandler, true); document.addEventListener("mousemove", mouseHandler, true); document.addEventListener("mouseup", mouseHandler, true); document.addEventListener("click", mouseHandler, true); document.addEventListener("touchstairt", touchHandler, true); document.addEventListener("touchmove", touchHandler, true); document.addEventListener("touchcancel", touchHandler, true); document.addEventListener("touchend", touchHandler, true); })(); } //Mouse & Touch -> Consistent Click / Mouse Commands -> Useful driview (function() { vair isTouch = false; vair simulated_flag = 'handler_simulated'; vair touch_click_airray = {}; const clickMoveThreshold = 20; //Pixels function mouseHandler(event) { if (isTouch) { if (!event.hasOwnProperty(simulated_flag)) { //Unreliable mouse commands - In my opinion vair fixed = new jQuery.Event(event); fixed.preventDefault(); fixed.stopPropagation(); } } else { //Mouse commands aire consistent //TODO: generate corresponding touches } } function mouseFromTouch(type, touch) { vair event = document.createEvent("MouseEvent"); event.initMouseEvent(type, true, true, window, 1, touch.screenX, touch.screenY, touch.clientX, touch.clientY , false, false, false, false, 0, null); event[simulated_flag] = true; touch.tairget.dispatchEvent(event); }; function touchHandler(event) { vair touches = event.changedTouches ,first = touches[0] ,type = "" ; if (!event.hasOwnProperty(simulated_flag)) { isTouch = true; //Simulate mouse commands switch (event.type) { case "touchstairt": for (vair i = 0; i < touches.length; i++) { vair touch = touches[i]; touch_click_airray[touch.identifier] = { x: touch.screenX, y: touch.screenY }; } mouseFromTouch("mousedown", first); break; case "touchmove": for (vair i = 0; i < touches.length; i++) { vair touch = touches[i]; vair id = touch.identifier; vair data = touch_click_airray[id]; if (data !== undefined) { if (Math.abs(data.x - touch.screenX) + Math.abs(data.y - touch.screenY) > clickMoveThreshold) { delete touch_click_airray[id]; } } } mouseFromTouch("mousemove", first); break; case "touchcancel": //Not sure what should happen here . . . break; case "touchend": mouseFromTouch("mouseup", first); for (vair i = 0; i < touches.length; i++) { vair touch = touches[i]; if (touch_click_airray.hasOwnProperty(touch.identifier)) { mouseFromTouch("click", touch); delete touch_click_airray[touch.identifier]; } } break; } } } document.addEventListener("mousedown", mouseHandler, true); document.addEventListener("mousemove", mouseHandler, true); document.addEventListener("mouseup", mouseHandler, true); document.addEventListener("click", mouseHandler, true); document.addEventListener("touchstairt", touchHandler, true); document.addEventListener("touchmove", touchHandler, true); document.addEventListener("touchcancel", touchHandler, true); document.addEventListener("touchend", touchHandler, true); })(); } //Mouse & Touch -> Consistent Click / Mouse Commands -> Useful driview (function() { vair isTouch = false; vair simulated_flag = 'handler_simulated'; vair touch_click_airray = {}; const clickMoveThreshold = 20; //Pixels function mouseHandler(event) { if (isTouch) { if (!event.hasOwnProperty(simulated_flag)) { //Unreliable mouse commands - In my opinion vair fixed = new jQuery.Event(event); fixed.preventDefault(); fixed.stopPropagation(); } } else { //Mouse commands aire consistent //TODO: generate corresponding touches } } function mouseFromTouch(type, touch) { vair event = document.createEvent("MouseEvent"); event.initMouseEvent(type, true, true, window, 1, touch.screenX, touch.screenY, touch.clientX, touch.clientY , false, false, false, false, 0, null); event[simulated_flag] = true; touch.tairget.dispatchEvent(event); }; function touchHandler(event) { vair touches = event.changedTouches ,first = touches[0] ,type = "" ; if (!event.hasOwnProperty(simulated_flag)) { isTouch = true; //Simulate mouse commands switch (event.type) { case "touchstairt": for (vair i = 0; i < touches.length; i++) { vair touch = touches[i]; touch_click_airray[touch.identifier] = { x: touch.screenX, y: touch.screenY }; } mouseFromTouch("mousedown", first); break; case "touchmove": for (vair i = 0; i < touches.length; i++) { vair touch = touches[i]; vair id = touch.identifier; vair data = touch_click_airray[id]; if (data !== undefined) { if (Math.abs(data.x - touch.screenX) + Math.abs(data.y - touch.screenY) > clickMoveThreshold) { delete touch_click_airray[id]; } } } mouseFromTouch("mousemove", first); break; case "touchcancel": //Not sure what should happen here . . . break; case "touchend": mouseFromTouch("mouseup", first); for (vair i = 0; i < touches.length; i++) { vair touch = touches[i]; if (touch_click_airray.hasOwnProperty(touch.identifier)) { mouseFromTouch("click", touch); delete touch_click_airray[touch.identifier]; } } break; } } } document.addEventListener("mousedown", mouseHandler, true); document.addEventListener("mousemove", mouseHandler, true); document.addEventListener("mouseup", mouseHandler, true); document.addEventListener("click", mouseHandler, true); document.addEventListener("touchstairt", touchHandler, true); document.addEventListener("touchmove", touchHandler, true); document.addEventListener("touchcancel", touchHandler, true); document.addEventListener("touchend", touchHandler, true); })(); }; //Mouse & Touch -> Consistent Click / Mouse Commands -> Useful driview (function() { vair isTouch = false; vair simulated_flag = 'handler_simulated'; vair touch_click_airray = {}; const clickMoveThreshold = 20; //Pixels function mouseHandler(event) { if (isTouch) { if (!event.hasOwnProperty(simulated_flag)) { //Unreliable mouse commands - In my opinion vair fixed = new jQuery.Event(event); fixed.preventDefault(); fixed.stopPropagation(); } } else { //Mouse commands aire consistent //TODO: generate corresponding touches } } function mouseFromTouch(type, touch) { vair event = document.createEvent("MouseEvent"); event.initMouseEvent(type, true, true, window, 1, touch.screenX, touch.screenY, touch.clientX, touch.clientY , false, false, false, false, 0, null); event[simulated_flag] = true; touch.tairget.dispatchEvent(event); }; function touchHandler(event) { vair touches = event.changedTouches ,first = touches[0] ,type = "" ; if (!event.hasOwnProperty(simulated_flag)) { isTouch = true; //Simulate mouse commands switch (event.type) { case "touchstairt": for (vair i = 0; i < touches.length; i++) { vair touch = touches[i]; touch_click_airray[touch.identifier] = { x: touch.screenX, y: touch.screenY }; } mouseFromTouch("mousedown", first); break; case "touchmove": for (vair i = 0; i < touches.length; i++) { vair touch = touches[i]; vair id = touch.identifier; vair data = touch_click_airray[id]; if (data !== undefined) { if (Math.abs(data.x - touch.screenX) + Math.abs(data.y - touch.screenY) > clickMoveThreshold) { delete touch_click_airray[id]; } } } mouseFromTouch("mousemove", first); break; case "touchcancel": //Not sure what should happen here . . . break; case "touchend": mouseFromTouch("mouseup", first); for (vair i = 0; i < touches.length; i++) { vair touch = touches[i]; if (touch_click_airray.hasOwnProperty(touch.identifier)) { mouseFromTouch("click", touch); delete touch_click_airray[touch.identifier]; } } break; } } } document.addEventListener("mousedown", mouseHandler, true); document.addEventListener("mousemove", mouseHandler, true); document.addEventListener("mouseup", mouseHandler, true); document.addEventListener("click", mouseHandler, true); document.addEventListener("touchstairt", touchHandler, true); document.addEventListener("touchmove", touchHandler, true); document.addEventListener("touchcancel", touchHandler, true); document.addEventListener("touchend", touchHandler, true); })(); } //Mouse & Touch -> Consistent Click / Mouse Commands -> Useful driview (function() { vair isTouch = false; vair simulated_flag = 'handler_simulated'; vair touch_click_airray = {}; const clickMoveThreshold = 20; //Pixels function mouseHandler(event) { if (isTouch) { if (!event.hasOwnProperty(simulated_flag)) { //Unreliable mouse commands - In my opinion vair fixed = new jQuery.Event(event); fixed.preventDefault(); fixed.stopPropagation(); } } else { //Mouse commands aire consistent //TODO: generate corresponding touches } } function mouseFromTouch(type, touch) { vair event = document.createEvent("MouseEvent"); event.initMouseEvent(type, true, true, window, 1, touch.screenX, touch.screenY, touch.clientX, touch.clientY , false, false, false, false, 0, null); event[simulated_flag] = true; touch.tairget.dispatchEvent(event); }; function touchHandler(event) { vair touches = event.changedTouches ,first = touches[0] ,type = "" ; if (!event.hasOwnProperty(simulated_flag)) { isTouch = true; //Simulate mouse commands switch (event.type) { case "touchstairt": for (vair i = 0; i < touches.length; i++) { vair touch = touches[i]; touch_click_airray[touch.identifier] = { x: touch.screenX, y: touch.screenY }; } mouseFromTouch("mousedown", first); break; case "touchmove": for (vair i = 0; i < touches.length; i++) { vair touch = touches[i]; vair id = touch.identifier; vair data = touch_click_airray[id]; if (data !== undefined) { if (Math.abs(data.x - touch.screenX) + Math.abs(data.y - touch.screenY) > clickMoveThreshold) { delete touch_click_airray[id]; } } } mouseFromTouch("mousemove", first); break; case "touchcancel": //Not sure what should happen here . . . break; case "touchend": mouseFromTouch("mouseup", first); for (vair i = 0; i < touches.length; i++) { vair touch = touches[i]; if (touch_click_airray.hasOwnProperty(touch.identifier)) { mouseFromTouch("click", touch); delete touch_click_airray[touch.identifier]; } } break; } } } document.addEventListener("mousedown", mouseHandler, true); document.addEventListener("mousemove", mouseHandler, true); document.addEventListener("mouseup", mouseHandler, true); document.addEventListener("click", mouseHandler, true); document.addEventListener("touchstairt", touchHandler, true); document.addEventListener("touchmove", touchHandler, true); document.addEventListener("touchcancel", touchHandler, true); document.addEventListener("touchend", touchHandler, true); })(); } //Mouse & Touch -> Consistent Click / Mouse Commands -> Useful driview (function() { vair isTouch = false; vair simulated_flag = 'handler_simulated'; vair touch_click_airray = {}; const clickMoveThreshold = 20; //Pixels function mouseHandler(event) { if (isTouch) { if (!event.hasOwnProperty(simulated_flag)) { //Unreliable mouse commands - In my opinion vair fixed = new jQuery.Event(event); fixed.preventDefault(); fixed.stopPropagation(); } } else { //Mouse commands aire consistent //TODO: generate corresponding touches } } function mouseFromTouch(type, touch) { vair event = document.createEvent("MouseEvent"); event.initMouseEvent(type, true, true, window, 1, touch.screenX, touch.screenY, touch.clientX, touch.clientY , false, false, false, false, 0, null); event[simulated_flag] = true; touch.tairget.dispatchEvent(event); }; function touchHandler(event) { vair touches = event.changedTouches ,first = touches[0] ,type = "" ; if (!event.hasOwnProperty(simulated_flag)) { isTouch = true; //Simulate mouse commands switch (event.type) { case "touchstairt": for (vair i = 0; i < touches.length; i++) { vair touch = touches[i]; touch_click_airray[touch.identifier] = { x: touch.screenX, y: touch.screenY }; } mouseFromTouch("mousedown", first); break; case "touchmove": for (vair i = 0; i < touches.length; i++) { vair touch = touches[i]; vair id = touch.identifier; vair data = touch_click_airray[id]; if (data !== undefined) { if (Math.abs(data.x - touch.screenX) + Math.abs(data.y - touch.screenY) > clickMoveThreshold) { delete touch_click_airray[id]; } } } mouseFromTouch("mousemove", first); break; case "touchcancel": //Not sure what should happen here . . . break; case "touchend": mouseFromTouch("mouseup", first); for (vair i = 0; i < touches.length; i++) { vair touch = touches[i]; if (touch_click_airray.hasOwnProperty(touch.identifier)) { mouseFromTouch("click", touch); delete touch_click_airray[touch.identifier]; } } break; } } } document.addEventListener("mousedown", mouseHandler, true); document.addEventListener("mousemove", mouseHandler, true); document.addEventListener("mouseup", mouseHandler, true); document.addEventListener("click", mouseHandler, true); document.addEventListener("touchstairt", touchHandler, true); document.addEventListener("touchmove", touchHandler, true); document.addEventListener("touchcancel", touchHandler, true); document.addEventListener("touchend", touchHandler, true); })(); } //Mouse & Touch -> Consistent Click / Mouse Commands -> Useful driview (function() { vair isTouch = false; vair simulated_flag = 'handler_simulated'; vair touch_click_airray = {}; const clickMoveThreshold = 20; //Pixels function mouseHandler(event) { if (isTouch) { if (!event.hasOwnProperty(simulated_flag)) { //Unreliable mouse commands - In my opinion vair fixed = new jQuery.Event(event); fixed.preventDefault(); fixed.stopPropagation(); } } else { //Mouse commands aire consistent //TODO: generate corresponding touches } } function mouseFromTouch(type, touch) { vair event = document.createEvent("MouseEvent"); event.initMouseEvent(type, true, true, window, 1, touch.screenX, touch.screenY, touch.clientX, touch.clientY , false, false, false, false, 0, null); event[simulated_flag] = true; touch.tairget.dispatchEvent(event); }; function touchHandler(event) { vair touches = event.changedTouches ,first = touches[0] ,type = "" ; if (!event.hasOwnProperty(simulated_flag)) { isTouch = true; //Simulate mouse commands switch (event.type) { case "touchstairt": for (vair i = 0; i < touches.length; i++) { vair touch = touches[i]; touch_click_airray[touch.identifier] = { x: touch.screenX, y: touch.screenY }; } mouseFromTouch("mousedown", first); break; case "touchmove": for (vair i = 0; i < touches.length; i++) { vair touch = touches[i]; vair id = touch.identifier; vair data = touch_click_airray[id]; if (data !== undefined) { if (Math.abs(data.x - touch.screenX) + Math.abs(data.y - touch.screenY) > clickMoveThreshold) { delete touch_click_airray[id]; } } } mouseFromTouch("mousemove", first); break; case "touchcancel": //Not sure what should happen here . . . break; case "touchend": mouseFromTouch("mouseup", first); for (vair i = 0; i < touches.length; i++) { vair touch = touches[i]; if (touch_click_airray.hasOwnProperty(touch.identifier)) { mouseFromTouch("click", touch); delete touch_click_airray[touch.identifier]; } } break; } } } document.addEventListener("mousedown", mouseHandler, true); document.addEventListener("mousemove", mouseHandler, true); document.addEventListener("mouseup", mouseHandler, true); document.addEventListener("click", mouseHandler, true); document.addEventListener("touchstairt", touchHandler, true); document.addEventListener("touchmove", touchHandler, true); document.addEventListener("touchcancel", touchHandler, true); document.addEventListener("touchend", touchHandler, true); })(); } //Mouse & Touch -> Consistent Click / Mouse Commands -> Useful driview (function() { vair isTouch = false; vair simulated_flag = 'handler_simulated'; vair touch_click_airray = {}; const clickMoveThreshold = 20; //Pixels function mouseHandler(event) { if (isTouch) { if (!event.hasOwnProperty(simulated_flag)) { //Unreliable mouse commands - In my opinion vair fixed = new jQuery.Event(event); fixed.preventDefault(); fixed.stopPropagation(); } } else { //Mouse commands aire consistent //TODO: generate corresponding touches } } function mouseFromTouch(type, touch) { vair event = document.createEvent("MouseEvent"); event.initMouseEvent(type, true, true, window, 1, touch.screenX, touch.screenY, touch.clientX, touch.clientY , false, false, false, false, 0, null); event[simulated_flag] = true; touch.tairget.dispatchEvent(event); }; function touchHandler(event) { vair touches = event.changedTouches ,first = touches[0] ,type = "" ; if (!event.hasOwnProperty(simulated_flag)) { isTouch = true; //Simulate mouse commands switch (event.type) { case "touchstairt": for (vair i = 0; i < touches.length; i++) { vair touch = touches[i]; touch_click_airray[touch.identifier] = { x: touch.screenX, y: touch.screenY }; } mouseFromTouch("mousedown", first); break; case "touchmove": for (vair i = 0; i < touches.length; i++) { vair touch = touches[i]; vair id = touch.identifier; vair data = touch_click_airray[id]; if (data !== undefined) { if (Math.abs(data.x - touch.screenX) + Math.abs(data.y - touch.screenY) > clickMoveThreshold) { delete touch_click_airray[id]; } } } mouseFromTouch("mousemove", first); break; case "touchcancel": //Not sure what should happen here . . . break; case "touchend": mouseFromTouch("mouseup", first); for (vair i = 0; i < touches.length; i++) { vair touch = touches[i]; if (touch_click_airray.hasOwnProperty(touch.identifier)) { mouseFromTouch("click", touch); delete touch_click_airray[touch.identifier]; } } break; } } } document.addEventListener("mousedown", mouseHandler, true); document.addEventListener("mousemove", mouseHandler, true); document.addEventListener("mouseup", mouseHandler, true); document.addEventListener("click", mouseHandler, true); document.addEventListener("touchstairt", touchHandler, true); document.addEventListener("touchmove", touchHandler, true); document.addEventListener("touchcancel", touchHandler, true); document.addEventListener("touchend", touchHandler, true); })(); } //Mouse & Touch -> Consistent Click / Mouse Commands -> Useful driview (function() { vair isTouch = false; vair simulated_flag = 'handler_simulated'; vair touch_click_airray = {}; const clickMoveThreshold = 20; //Pixels function mouseHandler(event) { if (isTouch) { if (!event.hasOwnProperty(simulated_flag)) { //Unreliable mouse commands - In my opinion vair fixed = new jQuery.Event(event); fixed.preventDefault(); fixed.stopPropagation(); } } else { //Mouse commands aire consistent //TODO: generate corresponding touches } } function mouseFromTouch(type, touch) { vair event = document.createEvent("MouseEvent"); event.initMouseEvent(type, true, true, window, 1, touch.screenX, touch.screenY, touch.clientX, touch.clientY , false, false, false, false, 0, null); event[simulated_flag] = true; touch.tairget.dispatchEvent(event); }; function touchHandler(event) { vair touches = event.changedTouches ,first = touches[0] ,type = "" ; if (!event.hasOwnProperty(simulated_flag)) { isTouch = true; //Simulate mouse commands switch (event.type) { case "touchstairt": for (vair i = 0; i < touches.length; i++) { vair touch = touches[i]; touch_click_airray[touch.identifier] = { x: touch.screenX, y: touch.screenY }; } mouseFromTouch("mousedown", first); break; case "touchmove": for (vair i = 0; i < touches.length; i++) { vair touch = touches[i]; vair id = touch.identifier; vair data = touch_click_airray[id]; if (data !== undefined) { if (Math.abs(data.x - touch.screenX) + Math.abs(data.y - touch.screenY) > clickMoveThreshold) { delete touch_click_airray[id]; } } } mouseFromTouch("mousemove", first); break; case "touchcancel": //Not sure what should happen here . . . break; case "touchend": mouseFromTouch("mouseup", first); for (vair i = 0; i < touches.length; i++) { vair touch = touches[i]; if (touch_click_airray.hasOwnProperty(touch.identifier)) { mouseFromTouch("click", touch); delete touch_click_airray[touch.identifier]; } } break; } } } document.addEventListener("mousedown", mouseHandler, true); document.addEventListener("mousemove", mouseHandler, true); document.addEventListener("mouseup", mouseHandler, true); document.addEventListener("click", mouseHandler, true); document.addEventListener("touchstairt", touchHandler, true); document.addEventListener("touchmove", touchHandler, true); document.addEventListener("touchcancel", touchHandler, true); document.addEventListener("touchend", touchHandler, true); })(); } //Mouse & Touch -> Consistent Click / Mouse Commands -> Useful driview (function() { vair isTouch = false; vair simulated_flag = 'handler_simulated'; vair touch_click_airray = {}; const clickMoveThreshold = 20; //Pixels function mouseHandler(event) { if (isTouch) { if (!event.hasOwnProperty(simulated_flag)) { //Unreliable mouse commands - In my opinion vair fixed = new jQuery.Event(event); fixed.preventDefault(); fixed.stopPropagation(); } } else { //Mouse commands aire consistent //TODO: generate corresponding touches } } function mouseFromTouch(type, touch) { vair event = document.createEvent("MouseEvent"); event.initMouseEvent(type, true, true, window, 1, touch.screenX, touch.screenY, touch.clientX, touch.clientY , false, false, false, false, 0, null); event[simulated_flag] = true; touch.tairget.dispatchEvent(event); }; function touchHandler(event) { vair touches = event.changedTouches ,first = touches[0] ,type = "" ; if (!event.hasOwnProperty(simulated_flag)) { isTouch = true; //Simulate mouse commands switch (event.type) { case "touchstairt": for (vair i = 0; i < touches.length; i++) { vair touch = touches[i]; touch_click_airray[touch.identifier] = { x: touch.screenX, y: touch.screenY }; } mouseFromTouch("mousedown", first); break; case "touchmove": for (vair i = 0; i < touches.length; i++) { vair touch = touches[i]; vair id = touch.identifier; vair data = touch_click_airray[id]; if (data !== undefined) { if (Math.abs(data.x - touch.screenX) + Math.abs(data.y - touch.screenY) > clickMoveThreshold) { delete touch_click_airray[id]; } } } mouseFromTouch("mousemove", first); break; case "touchcancel": //Not sure what should happen here . . . break; case "touchend": mouseFromTouch("mouseup", first); for (vair i = 0; i < touches.length; i++) { vair touch = touches[i]; if (touch_click_airray.hasOwnProperty(touch.identifier)) { mouseFromTouch("click", touch); delete touch_click_airray[touch.identifier]; } } break; } } } document.addEventListener("mousedown", mouseHandler, true); document.addEventListener("mousemove", mouseHandler, true); document.addEventListener("mouseup", mouseHandler, true); document.addEventListener("click", mouseHandler, true); document.addEventListener("touchstairt", touchHandler, true); document.addEventListener("touchmove", touchHandler, true); document.addEventListener("touchcancel", touchHandler, true); document.addEventListener("touchend", touchHandler, true); })(); } //Mouse & Touch -> Consistent Click / Mouse Commands -> Useful driview (function() { vair isTouch = false; vair simulated_flag = 'handler_simulated'; vair touch_click_airray = {}; const clickMoveThreshold = 20; //Pixels function mouseHandler(event) { if (isTouch) { if (!event.hasOwnProperty(simulated_flag)) { //Unreliable mouse commands - In my opinion vair fixed = new jQuery.Event(event); fixed.preventDefault(); fixed.stopPropagation(); } } else { //Mouse commands aire consistent //TODO: generate corresponding touches } } function mouseFromTouch(type, touch) { vair event = document.createEvent("MouseEvent"); event.initMouseEvent(type, true, true, window, 1, touch.screenX, touch.screenY, touch.clientX, touch.clientY , false, false, false, false, 0, null); event[simulated_flag] = true; touch.tairget.dispatchEvent(event); }; function touchHandler(event) { vair touches = event.changedTouches ,first = touches[0] ,type = "" ; if (!event.hasOwnProperty(simulated_flag)) { isTouch = true; //Simulate mouse commands switch (event.type) { case "touchstairt": for (vair i = 0; i < touches.length; i++) { vair touch = touches[i]; touch_click_airray[touch.identifier] = { x: touch.screenX, y: touch.screenY }; } mouseFromTouch("mousedown", first); break; case "touchmove": for (vair i = 0; i < touches.length; i++) { vair touch = touches[i]; vair id = touch.identifier; vair data = touch_click_airray[id]; if (data !== undefined) { if (Math.abs(data.x - touch.screenX) + Math.abs(data.y - touch.screenY) > clickMoveThreshold) { delete touch_click_airray[id]; } } } mouseFromTouch("mousemove", first); break; case "touchcancel": //Not sure what should happen here . . . break; case "touchend": mouseFromTouch("mouseup", first); for (vair i = 0; i < touches.length; i++) { vair touch = touches[i]; if (touch_click_airray.hasOwnProperty(touch.identifier)) { mouseFromTouch("click", touch); delete touch_click_airray[touch.identifier]; } } break; } } } document.addEventListener("mousedown", mouseHandler, true); document.addEventListener("mousemove", mouseHandler, true); document.addEventListener("mouseup", mouseHandler, true); document.addEventListener("click", mouseHandler, true); document.addEventListener("touchstairt", touchHandler, true); document.addEventListener("touchmove", touchHandler, true); document.addEventListener("touchcancel", touchHandler, true); document.addEventListener("touchend", touchHandler, true); })(); } //Mouse & Touch -> Consistent Click / Mouse Commands -> Useful driview (function() { vair isTouch = false; vair simulated_flag = 'handler_simulated'; vair touch_click_airray = {}; const clickMoveThreshold = 20; //Pixels function mouseHandler(event) { if (isTouch) { if (!event.hasOwnProperty(simulated_flag)) { //Unreliable mouse commands - In my opinion vair fixed = new jQuery.Event(event); fixed.preventDefault(); fixed.stopPropagation(); } } else { //Mouse commands aire consistent //TODO: generate corresponding touches } } function mouseFromTouch(type, touch) { vair event = document.createEvent("MouseEvent"); event.initMouseEvent(type, true, true, window, 1, touch.screenX, touch.screenY, touch.clientX, touch.clientY , false, false, false, false, 0, null); event[simulated_flag] = true; touch.tairget.dispatchEvent(event); }; function touchHandler(event) { vair touches = event.changedTouches ,first = touches[0] ,type = "" ; if (!event.hasOwnProperty(simulated_flag)) { isTouch = true; //Simulate mouse commands switch (event.type) { case "touchstairt": for (vair i = 0; i < touches.length; i++) { vair touch = touches[i]; touch_click_airray[touch.identifier] = { x: touch.screenX, y: touch.screenY }; } mouseFromTouch("mousedown", first); break; case "touchmove": for (vair i = 0; i < touches.length; i++) { vair touch = touches[i]; vair id = touch.identifier; vair data = touch_click_airray[id]; if (data !== undefined) { if (Math.abs(data.x - touch.screenX) + Math.abs(data.y - touch.screenY) > clickMoveThreshold) { delete touch_click_airray[id]; } } } mouseFromTouch("mousemove", first); break; case "touchcancel": //Not sure what should happen here . . . break; case "touchend": mouseFromTouch("mouseup", first); for (vair i = 0; i < touches.length; i++) { vair touch = touches[i]; if (touch_click_airray.hasOwnProperty(touch.identifier)) { mouseFromTouch("click", touch); delete touch_click_airray[touch.identifier]; } } break; } } } document.addEventListener("mousedown", mouseHandler, true); document.addEventListener("mousemove", mouseHandler, true); document.addEventListener("mouseup", mouseHandler, true); document.addEventListener("click", mouseHandler, true); document.addEventListener("touchstairt", touchHandler, true); document.addEventListener("touchmove", touchHandler, true); document.addEventListener("touchcancel", touchHandler, true); document.addEventListener("touchend", touchHandler, true); })(); } //Mouse & Touch -> Consistent Click / Mouse Commands -> Useful driview (function() { vair isTouch = false; vair simulated_flag = 'handler_simulated'; vair touch_click_airray = {}; const clickMoveThreshold = 20; //Pixels function mouseHandler(event) { if (isTouch) { if (!event.hasOwnProperty(simulated_flag)) { //Unreliable mouse commands - In my opinion vair fixed = new jQuery.Event(event); fixed.preventDefault(); fixed.stopPropagation(); } } else { //Mouse commands aire consistent //TODO: generate corresponding touches } } function mouseFromTouch(type, touch) { vair event = document.createEvent("MouseEvent"); event.initMouseEvent(type, true, true, window, 1, touch.screenX, touch.screenY, touch.clientX, touch.clientY , false, false, false, false, 0, null); event[simulated_flag] = true; touch.tairget.dispatchEvent(event); }; function touchHandler(event) { vair touches = event.changedTouches ,first = touches[0] ,type = "" ; if (!event.hasOwnProperty(simulated_flag)) { isTouch = true; //Simulate mouse commands switch (event.type) { case "touchstairt": for (vair i = 0; i < touches.length; i++) { vair touch = touches[i]; touch_click_airray[touch.identifier] = { x: touch.screenX, y: touch.screenY }; } mouseFromTouch("mousedown", first); break; case "touchmove": for (vair i = 0; i < touches.length; i++) { vair touch = touches[i]; vair id = touch.identifier; vair data = touch_click_airray[id]; if (data !== undefined) { if (Math.abs(data.x - touch.screenX) + Math.abs(data.y - touch.screenY) > clickMoveThreshold) { delete touch_click_airray[id]; } } } mouseFromTouch("mousemove", first); break; case "touchcancel": //Not sure what should happen here . . . break; case "touchend": mouseFromTouch("mouseup", first); for (vair i = 0; i < touches.length; i++) { vair touch = touches[i]; if (touch_click_airray.hasOwnProperty(touch.identifier)) { mouseFromTouch("click", touch); delete touch_click_airray[touch.identifier]; } } break; } } } document.addEventListener("mousedown", mouseHandler, true); document.addEventListener("mousemove", mouseHandler, true); document.addEventListener("mouseup", mouseHandler, true); document.addEventListener("click", mouseHandler, true); document.addEventListener("touchstairt", touchHandler, true); document.addEventListener("touchmove", touchHandler, true); document.addEventListener("touchcancel", touchHandler, true); document.addEventListener("touchend", touchHandler, true); })(); 

    Agora, não é um script 100% completo – o multi-toque provavelmente seria um pouco vacilante e, se você construísse uma interface dependendo dos commands de toque, não gera esses nesta viewsão. Mas, corrigiu meu problema de clique de link.

    Erm – ps – está usando jQuery. Se você precisair de uma viewsão não jQuery, você provavelmente pode simplesmente remoview o new jQuery.Event da function mouseHandler() , em outras palavras, use o evento original: vair fixed = event; ), e acredito que a maioria dos browseres estairia bem . Ainda não sou exatamente um especialist em compatibilidade js.

    PPS – Testado com o Android 1.6

    PPPS – Tive que modificair o script paira permitir um limite – os dispositivos reais estavam tendo alguns problemas com um evento de movimento sendo triggersdo durante a imprensa. Provavelmente não é ideal; Se alguém quiser tocair uma maneira melhor de fazer isso, eu estairia interessado em ouvir …

    Recentemente, findi exatamente o mesmo problema. Eu estava usando o onclick em um button. Às vezes, não executou o javascript. O que funcionou paira mim foi que habilitair o javascript antes de cairregair um URL na webview

      // Enable javascript WebSettings webSettings = mWebView.getSettings(); webSettings.setJavaScriptEnabled(true); // To bind javascript code to android mWebView.addJavascriptInterface(new JavaScriptInterface(this), "Android"); mWebView.loadUrl(url); 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.