To see if the Return key was touched I add onKeyPress to the HTML body tag like this
<body onKeyPress="return returnKeyPressed(event)">
There is a javascript function on the page that looks like this
function returnKeyPressed(event){
if(window.event.keyCode == 13) document.location = "returnkeypressed:";
return true;
}
And I have this in the class that is the webView delegate
- (BOOL)webView:(UIWebView*)aWebView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType{
NSString *requestString = [[request URL] absoluteString];
NSArray *components = [requestString componentsSeparatedByString:@":"];
NSString *theTask = (NSString *)[components objectAtIndex:0];
if([theTask isEqualToString:@"returnkeypressed"]) [aWebView endEditing:YES];
}
This just ends all editing in the webView, dismisses the keyboard, and removes focus from any specific textarea or input.
How to change the "label" of the Return key in a webView situation (to something like 'Done') is still a mystery to me. Ideas?
UPDATE:
I changed the javascript function to this
function returnKeyPressed(event){
if(event.srcElement.nodeName == 'INPUT' && window.event.keyCode == 13) document.location = "returnkeypressed:";
return true;
}
to allow the return key to function normally in textareas.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…