mark! UIwebview 通过jquery 和用户交互信息:
[objc] view plaincopy
- NSstring *html=@"<!DOCTYPE html PUBLIC ‘-//W3C//DTD XHTML 1.0 Transitional//EN‘ ‘http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd‘><html xmlns=‘http://www.w3.org/1999/xhtml‘><head runat=‘server‘><meta http-equiv=‘Content-Type‘ content=‘text/html; charset=UTF-8‘><title>阿速度发送地方</title><script src=‘http://d5mt.xj169.com/Miaosha/images/jquery-1.7.2.min.js‘ type=‘text/javascript‘></script><meta http-equiv=‘Cache-Control‘ content=‘must-revalidate,no-cache‘><meta id=‘viewport‘ name=‘viewport‘ content=‘width=device-width, maximum-scale=2,minimum-scale=1,initial-scale=1.000000‘><meta name=‘MobileOptimized‘ content=‘240‘></head><body> <script type=‘text/javascript‘>$(document).ready(function() {shows(); $(‘#imgurl‘).click(function (){shows();});}); function shows(){alert(‘123456789‘);}</script> <img style=‘height:20px; width:80px;‘ id=‘imgurl‘ src=‘https://www.google.com.hk/images/srpr/logo11w.png‘></img><p>1.asdfasdfasdfasdfasdfasdf</p><p>2.asdfasdfasdfasdfasdfasdf</p><p>3.asdfasdfasdfasdfasdfasdf</p><p>4.asdfasdfasdfasdfasdfasdf</p><p>5.asdfasdfasdfasdfasdfasdf</p><p>1.asdfasdfasdfasdfasdfasdf</p><p>2.asdfasdfasdfasdfasdfasdf</p><p>3.asdfasdfasdfasdfasdfasdf</p><p>4.asdfasdfasdfasdfasdfasdf</p><p>5.asdfasdfasdfasdfasdfasdf</p><p>1.asdfasdfasdfasdfasdfasdf</p><p>2.asdfasdfasdfasdfasdfasdf</p><p>3.asdfasdfasdfasdfasdfasdf</p><p>4.asdfasdfasdfasdfasdfasdf</p><p>5.asdfasdfasdfasdfasdfasdf</p><p>1.asdfasdfasdfasdfasdfasdf</p><p>2.asdfasdfasdfasdfasdfasdf</p><p>3.asdfasdfasdfasdfasdfasdf</p><p>4.asdfasdfasdfasdfasdfasdf</p><p>5.asdfasdfasdfasdfasdfasdf</p><p>1.asdfasdfasdfasdfasdfasdf</p><p>2.asdfasdfasdfasdfasdfasdf</p><p>3.asdfasdfasdfasdfasdfasdf</p><p>4.asdfasdfasdfasdfasdfasdf</p><p>5.asdfasdfasdfasdfasdfasdf</p></body></html>";
- [web loadHTMLString:html baseURL:nil];
这样 内容加载完后 自动执行弹窗 还有点击图片也可以弹窗, 这时候弹出提示框回属于系统自带的内容不是我们需要的,那么可以通过
- (void)webView:(UIWebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame; 这个方法来处理;具体如下:
[objc] view plaincopy
- - (void)webView:(UIWebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame {
- UIAlertView* customAlert = [[UIAlertView alloc] initWithTitle:@"提示信息" message:message delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
- [customAlert show];
- [customAlert autorelease];
- }
如此,我们还可以通过jquery 调用程序事件,前提是 你的触发事件要输出这个串:{window.location=‘image‘;} 通过下面的方法 调用
[objc] view plaincopy
- -(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
- {
- if([request.mainDocumentURL.relativePath isEqualToString:@"/image"])
- {
- NSLog(@"点击图片");
- }
- ]
时间: 2024-10-09 12:54:41