I've been lazy lately , I haven't blogged for a long time . Today, I met this wonderful problem in the project , be based on ionic Of ios Of hybird APP Can't use focus() Getting focus and keyboard issues .

problem : be based on ionic Of ios Of hybird APP Can't use focus() Getting focus and keyboard issues .

My code is as follows :

directive:

 .directive('focusMe', function($timeout) {
return {
link: function(scope, element) {
$timeout(function() {
element[0].focus();
},300);
}
};
})

html:

 <input focus-me type="search"   placeholder=" Search for ">

Such a simple piece of code , stay chrome The above debugging is normal , However, in ios I just can't get out .

Looking for solutions

And then I started google、baidu History , Flying in the ocean of knowledge , See a lot of strange phenomena , And it didn't solve my problem .

It's like  http://twilight.btlogs.com/how-to-focus-html-input-element-with-javascript-on-ios-and-android-mobile-safari/

It's mainly about , Only in functions that listen for user triggered time focus Only useful , You can click in and have a look .

I tried , Find this for hybird App It doesn't work either .

But it could be in the ordinary ios,html5 The page will take effect , I didn't try to , Please tell me if you have tried .

I wrote something like this , The following is also in line with what they said :

 .directive('focusMe', function($timeout) {
return {
link: function(scope, element) {
element[0].on('click',function(){
element[0].focus();
})
$timeout(function() {
element[0].trigger('click');
},300); }
};
})

Solution

original , stay App Configuration file for (config.xml), There is a default sentence in it

 <preference name="KeyboardDisplayRequiresUserAction" value="true" />

The general meaning of this is , The display of the keyboard needs to be triggered by the user , And it's set to true Of !!!

Now you know how to do it , Only need to value To change the value of false, Everything is settled .

 1 <preference name="KeyboardDisplayRequiresUserAction" value="false" />

Recently, I've been studying for a degree es6 grammar , It may be updated later es6 Learning notes of , If you are interested, let's discuss it together !

  

solve ionic stay ios Can't use focus,ios focus More articles on the issue of failure

  1. solve IOS safari stay input focus Pop up input method does not support position fixed The problem of

    This article is a reprint of We're doing mobile web When applied , Often used to using position:fixed Put one input Box is fixed at the bottom of the page as a question or search box . But in IOS Of safari and webview in , Yes position ...

  2. Mac Lower installation ionic and cordova, And generate iOS project

    For development HTML5, In addition to the latest use React Native Etc , At present, the first choice is stable ionic+Angularjs To develop iOS and android. Ionic(ionicframework A close to the original H ...

  3. about Sagit.Framework solve : Two way reference leads to IOS Memory leak ( in )- IOS Unknown Bug

    Preface : Last night or the night before , Write an article : about Sagit.Framework solve : Two way reference leads to IOS Memory leak ( On ) At the end of the article , A lot of strange questions !!! In order to solve these inexplicable problems , I'm fighting again 2 ...

  4. about Sagit.Framework solve : Two way reference leads to IOS Memory leak ( Next )- block It's willful to use self

    Preface : After dealing with the frame memory leak , See the first part : about Sagit.Framework solve : Two way reference leads to IOS Memory leak ( in )- IOS Unknown Bug It is found that there is a place in the business code where the memory is not released , The reason is simple : ...

  5. ios End position by fixed Invalid solutions

    Key code document.getElementById("searchInputbox").addEventListener('touchmove', handler, {pas ...

  6. Apple IOS Next text-shadow And box-shadow Invalid solutions

    Add the following style , Can solve Apple IOS Next text-shadow And box-shadow Failure problem -webkit-appearance: none

  7. ionic Default style android and ios differences

    ionicframework in android and ios There are some differences in the default style , There are instructions in the official documents , But often I can't remember . One . differences : 1.tab Location ,$ionicConfigProvider, tab ...

  8. Project support for both iOS 6 and iOS 7

    original text :https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/TransitionGuide/S ...

  9. iOS 7 UI Transition guide - Support continued iOS 6(iOS 7 UI Transition Guide - Supporting iOS 6)

    iOS 7 UI Transition Guide Preparing for Transition Before You Start Scoping the Project Supporting i ...

  10. iOS Development - compatible iOS 10

    1.Notification( notice ) since Notification After being introduced , Apple keeps updating and optimizing , But these updates and optimizations are just minor , Until now, iOS 10 Start a real major restructuring , This makes developers realize that UserN ...

Random recommendation

  1. iOS UIGestureRecognizer And UIMenuController( The content is based on iOS Programming )

    UIGestureRecognizer Object intercepts touch events that should have been handled by the view . When a UIGestureRecognizer After the object recognizes a specific gesture , Will send the specified message to the specified object .iOS SDK By default, if ...

  2. Huiwen Libsys Full version of the library management system +getshell

    Due to a very low-level code error , So that you can log in Libsys Any book system background , And because the code is not filtered, it can be directly getshell. The library management system has a large number of users , A large number of colleges and universities across the country are using this system . After testing 3.5-5.0 edition ...

  3. About Linux Of windows Directory mount

    today ,linux There's a little more space under the mainframe , No more hard drives , So the directory sharing is set in the physical machine , Add your own system's default account ( In order to increase the security of your host , I set up passwords with punctuation marks --- This is also the reason why the mount failed this time ...

  4. [COCOS2D-X]AssetsManager

    from :http://blog.csdn.net/xpwang168/article/details/8900764 Analysis of resource update mode I zip Package update advantage : Flow saving , Fast shortcoming : There are duplicate resources , Need to fight ...

  5. 1041: [HAOI2008] The whole point on the circle - BZOJ

    Description Find a given circle (x^2+y^2=r^2), How many points on the circle have integral coordinates .Input rOutput On the whole Sample Input4Sample Output4HINT n ...

  6. Impala 2、Impala Shell and Impala SQL

    1.Impala external Shell Impala external Shell Just don't go in Impala Inside , Directly executed ImpalaShell For example, through external Shell see Impala Help can be used : $ impala-s ...

  7. $digest already in progress

    Recently, I often encounter a small problem when writing projects , Change the view out of context , Usually we need to apply() Can be realized , The problem is that apply() The rear console reported an error :$digest already in progress: Then I put a ...

  8. Ajax Homology and cross domain

    ajax Cross domain access Client page var url = "http://172.16.91.121:81/FellIn/FellIn.aspx?Action=WXSave&WX_Store ...

  9. dropload.js( Pull up load plug-ins encountered in the process of using the pit )

    dropload.js Related introduction and use as well as demo For download, see :https://github.com/ximan/dropload ( The source of the original text is ) Before, because the project needs a pull-up loading effect , And then I came across the plug-in , ...

  10. Machine learning is one of the three swordsmen Pandas in DataFrame Basic operation

    Pandas Is based on Numpy  A tool of , It was created to solve the data analysis task .Pandas It includes a large number of databases and some standard data models , Provides the tools needed to operate large datasets efficiently .Pandas It provides a lot of services that can make us fast and convenient ...