2017-06-20 87 views
0

我有一個UIWebView,我正在使用本地鍵盤創建自定義文本編輯器。在UIWebview(iOS)中檢測返回按鈕

我試圖檢測當本機鍵盤上按下返回按鈕。我試圖在這個代碼:How to detect keyboard enter key?以及customize return key,但無法成功。我如何獲得回報?

HTML:

<!DOCTYPE html> 
<html> 
<head> 
<title>iOS Note Editor</title> 
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"> 

<script> 
    function returnKeyPressed(event){ 
     if(window.event.keyCode == 13) document.location = "returnkeypressed:"; 
      return true; 
     } 
    } 
</script> 

<style type="text/css"> 
    html, body {height: 100%;} 
    body { 
     margin: 0; 
    } 
#wrap { 
    height: 100%; 
    width: 100%; 
    overflow-y: scroll; 
    -webkit-overflow-scrolling: touch; 
} 

</style> 

<link rel="stylesheet" type="text/css" href="quill.snow.css"> 
<link rel="stylesheet" type="text/css" href="quill.bubble.css"> 
<link rel="stylesheet" type="text/css" href="quill.core.css"> 
<link rel="stylesheet" type="text/css" href="style.css"> 
<meta charset="utf-8"> 
</head> 
<body onKeyPress="return returnKeyPressed(event)" style="padding-top:0px;margin-top:0px;"> 
<div id="wrap"> 
<div id="editor-container" style="padding:0px;margin-top:0px;font-family:'GothamPro-Light';font-size: 15px;"></div> 
</div> 
<script type="text/javascript" src="quill.core.js"></script> 
<script type="text/javascript" src="quill.min.js"></script> 
<script type="text/javascript" src="quill.js"></script> 
<script type="text/javascript" src="jquery.min.js"></script> 
<script type="text/javascript" src="ios_note_editor.js"></script> 
</body> 
</html> 

.M

//Not being called 
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{ 
    NSLog(@"webView shouldStartLoadWithRequest"); 
} 

回答

0

body onKeyPress時改爲onKeyDown修復該問題。一個字頭疼的小時數