touchmove event in Safari/iOS5/iPad disables contenteditable - any workaround?

1.1k Views Asked by At

I have a serious problem in Safari on iPad. The new contenteditable features doesn't seem to work with touchmove event! code:

 ...
 <script>
function doNothing(event) { return; }

function initIFrame() {
    var iframe=document.getElementById("iframeedit");
    iframe.contentWindow.document.designMode="on";      
    iframe.contentWindow.document.addEventListener("touchmove", doNothing, true);
}
</script>
</head>
<body onload="initIFrame()">
<iframe style="width:500ppx;height:200px" src="content.html" id="iframeedit"></iframe>
...

By adding touchmove somewhere to the document the editable content can not be edited anymore after a touchmove (hold finger down to get the magnifier). The cursor can be set but typing by onscreen keyboard is not allowed anymore.

Test script (for iPad + iOS5): http://flyingdog.biz/tests/ipad/test2.html

Another test script which is working: http://flyingdog.biz/tests/ipad/test1.html

As you can see in that other script I put a few lines of text in front of iFrame - very strange! I am looking for another/better workaround or did I have done something wrong? Without the touchmove event it is working but I need this for a good editing experience.

1

There are 1 best solutions below

1
On

I found a workaround for this bug: It seems that the iframe document looses the focus after a touch event, especially when the copy&paste menu appears. To workaround this bug add a keydown event handler to the iframe-document and reset the focus to the document:

var iframeDoc = $(iframe.contentWindow.document);
iframeDoc.keydown(function(event) {
    iframe.contentWindow.focus();
});

This fixes the bug mostly for me. Only if the user types very fast (e.g. on a connected bluetooth keyboard) it can happen that some keystrokes are lost, because the javascript keydown handler execution is a little bit delayed on the iPad.