Looking for ibooks html input alternative

2019-08-16 16:31发布

In IOS5 on the iPad, iPad2 etc. iBooks accepted <input type="color"> as a way to prompt the keyboard to display when you clicked on an input field, to say, type in the answer to a question. I've just recently updated to IOS6, and this workaround no longer seems to be working. I tried using the JavaScript I found here - http://www.linkedin.com/groups/How-Show-iPads-Keyboard-when-3877009.S.84287009

<script type="text/javascript"> 

function iPadTouchHandler(event) { 
var type = "", 
button = 0; /*left*/ 

if (event.touches.length > 1) 
return; 

switch (event.type) { 
case "touchstart": 

// OLD: On iPad2 clicking on a text input field did not show the keyboard 
//  if ($(event.changedTouches[0].target).is("select")) { 
// NEW: Now on iPad2 the touchstart-Event on input fields is ignored and everything         works fine 
// change my by Roland Caspers, Scheer Management 
if ($(event.changedTouches[0].target).is("select") ||     $(event.changedTouches[0].target).is("input")) { 

return; 
} 
iPadTouchStart(event); /*We need to trigger two events here to support one touch drag     and drop*/ 
event.preventDefault(); 
return false; 
break; 
</script> 

However this code seems to be outdated and relevant to IOS5. I know of a workaround, which is to put the page with the input into an iFrame, in that case you can just use <input type="text">, however I'd prefer to stay away from iFrames as they tend to move the content around depending on where the input box is. Any thoughts as to other possible solutions or workarounds? Tyvm :)

2条回答
可以哭但决不认输i
2楼-- · 2019-08-16 16:35

I struggled with this same problem in iBooks on iOS 7. The tricky part was, that iBooks probably makes all text input fields disabled by default. We are using prototype.js, so here is my solution written for prototype:

$('my-input-field-id').observe('touchstart', function(event) {
    var element = event.element();
    if (element.disabled)
        element.disabled = false;
    element.focus();
    event.stop();
});

So just listen for the 'touchstart' event on the input field and enable and focus the field when touched. It works for ordinary text fields (<input type="text">). Simple :-).

查看更多
萌系小妹纸
3楼-- · 2019-08-16 16:49

I am also Facing the same issue on iOS6 for , the same is working perfectly on the <iframe> tag. But it omits the images & style and etc.

Review the code "http://www.linkedin.com/groups/How-Show-iPads-Keyboard-when-3877009.S.84287009", I feel some thing has to modify on below condition:

($(event.changedTouches[0].target).is("select") ||     $(event.changedTouches[0].target).is("input"))

I'd be great if anyone provide the earlier response.

Thanks

查看更多
登录 后发表回答