English 中文(简体)
如何发现移动虚拟板
原标题:jquery mobile how to detect if mobile virtual keyboard is opened

在机动装置中,当我打开一页并选择一个投入箱时,虚拟键盘是开放的,我想把这次活动赶上我的工作。

移动浏览器是否界定了任何活动处理方法以实现这一目标?

因此,当钥匙板开张时,我要履行我的习惯职能,在网页上展示/展示一些信使。

成就

最佳回答

First jQuery Mobile does not have any pre-defined event handler for this case. You will need to figure out the way yourself.

<>Android>

When virtual keyboard is open, it fires windows resize event. So you can check if the sum of windows width and height changed to detect keyboard is open or not.

iOS

这不是火上覆,的事件,因此,正如“RamizWachtler”所提到,仅仅要约束着重点和模糊事件。

因此,我在此有几部法典:

您仅将自己的操作代码添加到onKey板OnOff()功能中。

function onKeyboardOnOff(isOpen) {
    // Write down your handling code
    if (isOpen) {
        // keyboard is open
    } else {
        // keyboard is closed
    }
}

var originalPotion = false;
$(document).ready(function(){
    if (originalPotion === false) originalPotion = $(window).width() + $(window).height();
});

/**
 * Determine the mobile operating system.
 * This function returns one of  iOS ,  Android ,  Windows Phone , or  unknown .
 *
 * @returns {String}
 */
function getMobileOperatingSystem() {
    var userAgent = navigator.userAgent || navigator.vendor || window.opera;

      // Windows Phone must come first because its UA also contains "Android"
    if (/windows phone/i.test(userAgent)) {
        return "winphone";
    }

    if (/android/i.test(userAgent)) {
        return "android";
    }

    // iOS detection from: http://stackoverflow.com/a/9039885/177710
    if (/iPad|iPhone|iPod/.test(userAgent) && !window.MSStream) {
        return "ios";
    }

    return "";
}

function applyAfterResize() {

    if (getMobileOperatingSystem() !=  ios ) {
        if (originalPotion !== false) {
            var wasWithKeyboard = $( body ).hasClass( view-withKeyboard );
            var nowWithKeyboard = false;

                var diff = Math.abs(originalPotion - ($(window).width() + $(window).height()));
                if (diff > 100) nowWithKeyboard = true;

            $( body ).toggleClass( view-withKeyboard , nowWithKeyboard);
            if (wasWithKeyboard != nowWithKeyboard) {
                onKeyboardOnOff(nowWithKeyboard);
            }
        }
    }
}

$(document).on( focus blur ,  select, textarea, input[type=text], input[type=date], input[type=password], input[type=email], input[type=number] , function(e){
    var $obj = $(this);
    var nowWithKeyboard = (e.type ==  focusin );
    $( body ).toggleClass( view-withKeyboard , nowWithKeyboard);
    onKeyboardOnOff(nowWithKeyboard);
});

$(window).on( resize orientationchange , function(){
    applyAfterResize();
});
问题回答

我猜想你们对我的回答感到谨慎,因为你会做得更好,但这里是:

$(document).on( focus blur ,  select, textarea, input , function(e){
  if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ){
    //your function
  }
  else{
    //the opposite think you want to do
  }
});




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签