I have webviews which are representing blog posts. Some of these contain images.
So, I'd like to catch the user clicking on the images to display them alone.
Therefore, I have this script:
function clickOrigin(e){
var target = e.target;
var tag = [];
tag.tagType = target.tagName.toLowerCase();
tag.tagClass = target.className.split(' ');
tag.id = target.id;
tag.parent = target.parentNode.tagName.toLowerCase();
return tag;
}
var tagsToIdentify = 'img';
document.body.onclick = function(e){
elem = clickOrigin(e);
// for testing
document.body.style.backgroundColor = "red";
if (elem.tagType == tagsToIdentify) {
javascript:window.location=this.src;
// alert("IMAGE HAS BEEN CLICKED!");
return false; // or do something else.
}
};
After some reading, I stumbled across this: programmatic click in Android WebView
But I don't get this to work for me. How can I achieve my goal? The script is executed, I've set javascript to enabled and also added a WebChromeClient. Thanks!