0

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!

Marcel
  • 917
  • 3
  • 19
  • 48
  • checkt this: https://stackoverflow.com/a/4075955/5110536 – Usman Rana Jul 14 '17 at 12:27
  • @UsmanRana well, I've seen this as well, but the problem is, that I can only edit the js, not the html, and so I can't specifically set the onclick methods as shown in the link you provided. – Marcel Jul 14 '17 at 12:38
  • it can't be done in you don't have access to html editing because the method of js triggers from the html. If you can't modify html on site then try by loading html as edit it programmatically and then set in WebView , it may help – Usman Rana Jul 14 '17 at 12:52

0 Answers0