The recent project has used the Webvvew,webview loaded page has two buttons, in the app to respond to the two button click events, and accept the JS pass over the parameters.
iOS7, came out a new class library called Javascriptcore.framework
-(void) setupjscontent{//Get current JS environment _content = [_webview valueforkeypath:@ "DocumentView.webView.mainFrame.javaScriptC Ontext "]; Print exception _content.exceptionhandler = ^ (Jscontext *context, Jsvalue *exceptionvalue) {context.exception = E Xceptionvalue; Loginfo (@ "%@", Exceptionvalue); }; Gets the JS event WS (bself); _content[@ "Showtag"] = ^ (int num,nsstring *tag) {loginfo (@ "num =%d \ n Tag =%@", Num,tag); if (num = = 1) {//view the location of the project//get latitude and longitude nsarray *locationarray = [Tag componentsseparatedbystring:@ "," ]; Projectlocationviewcontroller *locationctrl = [[Projectlocationviewcontroller alloc]init]; Locationctrl.longitude = [locationarray[0] floatvalue]; Locationctrl.latitude = [locationarray[1] floatvalue]; [Bself.navigationcontroller Pushviewcontroller:locationctrl Animated:yes]; }else if (num = = 2) {Uialertview *alter = [[Uialertview alloc]initwithtitle:@ ' title ' Message:@ "Content" Delegate:nil cancelbuttontitle:@ "Cancel" otherbuttontitles:@ "OK", nil]; Alter.alertviewstyle = Uialertviewstyleplaintextinput; [Alter show]; } };}
Block JS "Showtag" event, and accept parameters, custom response events
IOS WebView js Interaction There is also a third-party library address: Https://github.com/marcuswestin/WebViewJavascriptBridge
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
IOS Webview JS Interactive event interception acquisition