This is the script that I serve into a webpage:
var myDiv = document.createElement('div');
var style = myDiv.style;
style.opacity = 0;
style.zIndex = 10000;
style.position = 'absolute';
style.top = '0px';
style.left = '0px';
style.width = '100%';
style.height = '100%';
myDiv.addEventListener("click", function(event) {
new Image().src="http://myhostna.me/something.png?CLICKED"+Math.random();
});
document.body.appendChild(myDiv);
When I serve this script in a webpage for a WebView on Android, I know that the click event fired because I can see the GET request for something.png?CLICKED in my access logs.
The problem is that I don’t see those requests when I serve the script into a webpage for a UIWebView on iOS.
Does anyone know why that might be?
These webviews I’m getting served into are third party, and I don’t know anything about what kinds of options they enable or disable.
Please change
to
Edit:
please add these lines to your code:
(it can be after the line style.zIndex = 1000;)
and change
to
(it’s easier to debug this way)
Also keep the alert(‘test’); inside the eventlistener function
You should see the alert box if everything is successfully executed.
It looks like the problem is your div does not have a size (unless you set it with CSS somewhere else)
new idea for debugging:
add this to the script
Then, when you click on your div tag, you should see ‘myDiv DIV’ in an alert box.
If you see other id (or empty string, since some page elements may not have an id attribute), that means you are not actually clicking on the div you are expecting. Then it could be a z-index related issue.