Looking for ibooks html input alternative

有些话、适合烂在心里 提交于 2019-12-25 03:00: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 :)


回答1:


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




回答2:


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 :-).



来源:https://stackoverflow.com/questions/12604869/looking-for-ibooks-html-input-alternative

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!