javascript - Call touch event on parent from iframe -
i'm trying call touch move event when user interacts iframe.
this code @ top level page contains iframe.
var myiframe = document.getelementbyid('iframe'); var myiframedoc = myiframe.contentwindow.document; myiframedoc.addeventlistener('touchmove', function(event){ console.log('iframe touched'); var e = document.createevent('touchevent'); //e.touches = [{pagex: 10, pagey: 10}]; //e.inittouchevent('touchstart', true, true); e.inituievent('touchstart', true, true); }, false);
so when user touch moves on iframe call 1 of events below (also @ top level page).
document.addeventlistener("touchmove", function(event){ alert('touchmove'); }); document.addeventlistener("touchstart", function(event){ alert('touchstart'); }); document.addeventlistener("touchend", function(event){ alert('touchend'); });
however touch events don't fire on parent layer... console log works fine, picking iframe touchmove, touchevent part doesn't seem working.
in short, need able events fire though user has touched parent page when interact iframe.
you not dispatching event. had create mouseevent
.
document.addeventlistener("touchstart", function (event) { alert('touchstart'); }); // fix 1 (test in mobile, may need feature detected) // or not work reliably across browsers, clients need touchevent var e = document.createevent('mouseevent'); e.inituievent('touchstart', true, true); //fix 2 document.dispatchevent(e);
Comments
Post a Comment