【问题标题】:Detect return button in UIWebview (iOS)检测 UIWebview (iOS) 中的返回按钮
【发布时间】:2017-06-20 18:38:00
【问题描述】:

我有一个 UIWebView,我正在创建一个带有本机键盘的自定义文本编辑器。

我正在尝试检测何时按下本机键盘上的返回按钮。我尝试了以下代码: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");
}

【问题讨论】:

    标签: ios uiwebview keyboard


    【解决方案1】:

    body onKeyPress 更改为 onKeyDown 可解决此问题。一个字头疼好几个小时

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-03
      • 1970-01-01
      相关资源
      最近更新 更多