【发布时间】:2011-06-23 15:19:39
【问题描述】:
我有一个 HTML 内容如下:
<html>
<head>
<meta name=viewport content=width=320/>
<script>
function imageClicked(){
var clicked=true;
window.location="/click/"+clicked;
}
</script>
</head>
<body>
<center><h1>This is Page One</h1></center>
<center><a href="javascript:void(0)" onMouseDown="imageClicked()"><IMG SRC="divers-circle.jpg">
</a></center>
</center><br><br>
<center>Scuba divers</center>
</body>
</html>
HTML 已正确加载到 UIWebView,因为它是本地文件:
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:((WebPageObj *)obj).webPath ofType:@"html"]isDirectory:NO]]];
webView.dataDetectorTypes = UIDataDetectorTypeAll;
现在,当我单击图像时,它会识别单击,但我如何在 Xcode 中实现操作,例如,打开另一个视图或警报?
顺便说一句,我是根据解释一些概念的教程做的,这里是链接: http://www.codeproject.com/KB/iPhone/iPhoneDevReader.aspx
但是,它在 Xcode 中创建了 HTML,在我的例子中,我加载了 HTML,因此,我需要以某种方式读取 HTML 中的脚本以包含以下内容:
if ( [request.mainDocumentURL.relativePath isEqualToString:@"/click/false"] ) {
NSLog( @"not clicked" );
return false;
}
if ( [request.mainDocumentURL.relativePath isEqualToString:@"/click/true"] ) { //the image is clicked, variable click is true
NSLog( @"image clicked" );
UIAlertView* alert=[[UIAlertView alloc]initWithTitle:@"JavaScript called"
message:@"You've called iPhone provided control from javascript!!" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil];
[alert show];
[alert release];
return false;
}
return true;
}
什么方法可以帮助我做到这一点?以及我应该把它放在哪里,因为我使用的是 ScrollView,然后在调用页面时加载 WebView。
提前致谢。
【问题讨论】:
标签: java html xcode uiwebview html-parsing