在 webView Objective C 上的 ASP 页面上检测 onclick
Detecting onclick on an ASP page on webView Objective C
我正在为我的服务器页面使用 Classic ASP
。在 webView
上加载以下 URL 时。当用户使用 - (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
单击 webView
时,我将检测到 link
如果在 the webView
上单击新的 URL link 时检测到 classbook.asp
,我将触发 segue 加载新的 VC
并加载新的 webView
然而,在 webView
触发器上还有另一个 google 映射 link,由以下 Classic ASP onclick
代码触发。
如何检测此 google 地图 link 在 webView
上的点击时间?目前,上述用于检测URLlink的方法无法检测onclick
服务器经典 ASP
<div id="map" onclick="window.open('http://maps.google.com/maps?q=<%=sLat%>,<%=sLongi%>(<%=sFCName%>)', '_system');"></div>
Objective C
@interface ClassesDet (){
AppDelegate *appDelegate;
NSString *sURL;
NSString *sURLFav;
}
@end
@implementation ClassesDet
@synthesize webView;
- (void)viewDidLoad {
[super viewDidLoad];
sURL = @"https://www.share-fitness.com/apps/class_det.asp?classcode=CLS100032&access=C&memcode=SF100035&catcode=YG&fccode=KL00059&dtpclass=24/04/2018&tpfrom=20:15&fav=false&lang=EN&encode=20a728210f0869f04aab6cf1682881816a36f0bd47cc894ac4d8dd22dd0ded24"
NSURL *url = [NSURL URLWithString:sURL];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
[webView setDelegate:(id<UIWebViewDelegate>)self];
[webView loadRequest:urlRequest];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
ClassBook *target = segue.destinationViewController;
if ([segue.identifier isEqualToString:@"ClassBook"]) {
NSLog(@" To ClassBook sURL : %@", sURL);
target.urlString = sURL;
} else {
NSLog(@" Else to Other VC and the sURL : %@", sURL);
target.urlString = sURL;
}
}
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
NSURL *URL = [request URL];
NSString *theString = [URL absoluteString];
NSRange match;
NSLog(@"The URL Clicked : %@", sURL);
match = [theString rangeOfString: @"classbook.asp"];
//---If the URL string does not contain classbook.asp meaning it is loading the webview.
if (match.location == NSNotFound) {
NSLog(@"Load the webView with this sURL : %@", sURL);
return YES; //---Load webview, the URL will be sURL nothing to do with theString
} else {
sURL = theString;
NSLog(@"Trigger the Segue ClassBook and pass the sURL : %@ Over ",sURL );
//---Calling the following method will trigger the segue and redirect to another viewController.
[self performSegueWithIdentifier:@"ClassBook" sender:self];
return NO; //---Don't load the webview
}
}
@end
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
if ([webView.request.URL.absoluteString containsString:@"http://maps.google.com/maps?q"]) {
//Your logic if require
}
else {
//Your logic if require
}
return YES;
}
查看 this answer. 您遇到的问题是 shouldStartLoadWithRequest:
没有在 JavaScript window.open()
上被调用。 link 中的答案提供了一种确保您的代码被调用的方法。我原以为其中一种委托方法会捕捉到这一点,但现在我看不到了。也许我在想 WKWebView
。
我正在为我的服务器页面使用 Classic ASP
。在 webView
上加载以下 URL 时。当用户使用 - (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
单击 webView
时,我将检测到 link
如果在 the webView
上单击新的 URL link 时检测到 classbook.asp
,我将触发 segue 加载新的 VC
并加载新的 webView
然而,在 webView
触发器上还有另一个 google 映射 link,由以下 Classic ASP onclick
代码触发。
如何检测此 google 地图 link 在 webView
上的点击时间?目前,上述用于检测URLlink的方法无法检测onclick
服务器经典 ASP
<div id="map" onclick="window.open('http://maps.google.com/maps?q=<%=sLat%>,<%=sLongi%>(<%=sFCName%>)', '_system');"></div>
Objective C
@interface ClassesDet (){
AppDelegate *appDelegate;
NSString *sURL;
NSString *sURLFav;
}
@end
@implementation ClassesDet
@synthesize webView;
- (void)viewDidLoad {
[super viewDidLoad];
sURL = @"https://www.share-fitness.com/apps/class_det.asp?classcode=CLS100032&access=C&memcode=SF100035&catcode=YG&fccode=KL00059&dtpclass=24/04/2018&tpfrom=20:15&fav=false&lang=EN&encode=20a728210f0869f04aab6cf1682881816a36f0bd47cc894ac4d8dd22dd0ded24"
NSURL *url = [NSURL URLWithString:sURL];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
[webView setDelegate:(id<UIWebViewDelegate>)self];
[webView loadRequest:urlRequest];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
ClassBook *target = segue.destinationViewController;
if ([segue.identifier isEqualToString:@"ClassBook"]) {
NSLog(@" To ClassBook sURL : %@", sURL);
target.urlString = sURL;
} else {
NSLog(@" Else to Other VC and the sURL : %@", sURL);
target.urlString = sURL;
}
}
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
NSURL *URL = [request URL];
NSString *theString = [URL absoluteString];
NSRange match;
NSLog(@"The URL Clicked : %@", sURL);
match = [theString rangeOfString: @"classbook.asp"];
//---If the URL string does not contain classbook.asp meaning it is loading the webview.
if (match.location == NSNotFound) {
NSLog(@"Load the webView with this sURL : %@", sURL);
return YES; //---Load webview, the URL will be sURL nothing to do with theString
} else {
sURL = theString;
NSLog(@"Trigger the Segue ClassBook and pass the sURL : %@ Over ",sURL );
//---Calling the following method will trigger the segue and redirect to another viewController.
[self performSegueWithIdentifier:@"ClassBook" sender:self];
return NO; //---Don't load the webview
}
}
@end
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
if ([webView.request.URL.absoluteString containsString:@"http://maps.google.com/maps?q"]) {
//Your logic if require
}
else {
//Your logic if require
}
return YES;
}
查看 this answer. 您遇到的问题是 shouldStartLoadWithRequest:
没有在 JavaScript window.open()
上被调用。 link 中的答案提供了一种确保您的代码被调用的方法。我原以为其中一种委托方法会捕捉到这一点,但现在我看不到了。也许我在想 WKWebView
。