IOS调用UIWebView中的javascript方法

吴经略
2023-12-01

1、初始化webview, 同时加载本地html代码片段,并且设置 UIWebViewDelegate 

[webView loadHTMLString:@"Hello World <script type=\"text/javascript\">function showHello(){return \"hello World 123\"}</script>" baseURL:nil];  
webView.delegate = self;  


2、再  -( void )webViewDidFinishLoad:( UIWebView *)webView 代理方法中通过oc调用js

-(void)webViewDidFinishLoad:(UIWebView *)webView {
    UIWebView *webview = [[approvalCopiesView subviews] objectAtIndex:0];
    NSLog(@"------%@", [webview stringByEvaluatingJavaScriptFromString:@"showHello();"]);
}


 类似资料: