/*
1. OC 調用 JS 只需在所需要傳值的地方獲取到JS中的點擊方法即可
例如: 點擊方法是下面的這個 functionAction
*/
- (void)functionAction {
//如果需要傳遞參數 給 JS,則初始化參數
NSString *str2 = @"1234mkfg";
NSString *str3 = @"kdsfj";
//傳參數
[_webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"func('%@', '%@');", str2, str3]];
}
- 用蘋果自帶的返回鍵按鈕處理如下(自定義的返回按鈕)
- (void)back:(UIBarButtonItem *)bon{
if ([self.webView canGoBack]) {
[self.webView goBack];
}else{
[self.view resignFirstResponder];
[self.navigationController popViewControllerAnimated:YES];
}
}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
NSString * requestString = [[request URL] absoluteString];
requestString = [requestString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
//獲取H5頁面里面按鈕的操作方法,根據這個進行判斷返回是內部的還是push的上一級頁面
if ([requestString hasPrefix:@"goback:"]) {
[self.navigationController popViewControllerAnimated:YES];
}else{
[self.webView goBack];
}
return YES;
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
[SVProgressHUD dismiss];
NSString * title = [webView stringByEvaluatingJavaScriptFromString:@"document.title"];//獲取當前頁面的title
self.title = title;
//獲取當前網頁的html
self.currentURL = webView.request.URL.absoluteString;
NSLog(@"title-%@--url-%@--",self.title,self.currentURL);
NSString *lJs = @"document.documentElement.innerHTML";
self.currentHTML = [webView stringByEvaluatingJavaScriptFromString:lJs];
}
最后編輯于 :
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。