1. 在webview讀取網頁中,在須要點擊的url中添加onclick()事件 web
window.location="/alert"; //引號中能夠改爲本身想設置的字符 網絡
2.給本地webView添加 UIWebViewDelegate url
添加以下方法: spa
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType { if ([request.mainDocumentURL.relativePath isEqualToString:@"/alert"]) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"本地代碼執行" delegate:self cancelButtonTitle:@"肯定" otherButtonTitles: nil]; [alert show]; return false; //執行本地代碼,返回false不讓網頁讀取網絡資源 } return true; //如沒有location對應的屬性,則讀取網絡相關資源 }