Using Click() On Links In Android Stock Browser Not Working
I want to trigger a click on a link with JavaScript but have problems getting it to work on the Android Stock Browser. The following code works fine in Chrome (Desktop, Mac) and Sa
Solution 1:
I found the solution here. Its pure JS, not jquery, but might help to solve missing click()
on android stock browsers:
<ahref="http://stackoverflow.com/"id="link">click here</a><scripttype="text/javascript">//same as: document.getElementById("link").click()var clickEvent = document.createEvent('MouseEvent');
clickEvent.initEvent('click', true, true);
document.getElementById("link").dispatchEvent(clickEvent);
</script>
Solution 2:
you need to convert your click events to touch events using Jquery like below
<scripttype="text/javascript">jQuery(document).ready(function()
{
jQuery('#a').bind("touchstart touchend touchmove click",function(event)
{
event.preventDefault();
jQuery('#b').click();
});
jQuery('#b').bind("touchstart touchend touchmove click",function(event)
{
event.preventDefault();
alert('Test');
});
});
</script>
Post a Comment for "Using Click() On Links In Android Stock Browser Not Working"