How to detect keyboard enter key?

前端 未结 4 660
广开言路
广开言路 2021-01-16 13:50

I have on UIWebView in that i am allowing editing at runtime.

Now when i click on UIWebView then iPad keyboard opens for writing, now my re

4条回答
  •  广开言路
    2021-01-16 14:08

    I done my work by javascript like this...

    In HTML file

    function returnEnterPress(e){
         var key;     
         if(window.event)
              key = window.event.keyCode; //IE
         else
              key = e.which; //firefox     
              // ENTER KEY MUNBER IS 13 // KD
         if(key == 13)
         {
            window.location.href = 'enterClicked/0';
         }
         else
         {
             var range = window.getSelection().getRangeAt(0).endOffset;
             if(range == 0)
             {
                window.location.href = 'enterClicked/'+range;
             }
         }
         return true;
    }
    
    
    

    In my Objective-c Code

    - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
    
        if([[[request URL] absoluteString] rangeOfString:@"enterClicked"].location!=NSNotFound)    // When "enterClicked" found
        {
            //Do your desired work
            return NO;
        }
    }
    

提交回复
热议问题