【问题标题】:Detecting onclick on an ASP page on webView Objective C在 webView Objective C 上检测 ASP 页面上的 onclick
【发布时间】:2018-04-24 08:56:38
【问题描述】:

我正在为我的服务器页面使用Classic ASP。在webView 上加载以下 URL 时。当用户使用- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType 点击webView 时,我将检测到链接 如果在the webView 上点击新的 URL 链接时检测到classbook.asp,我将触发一个 segue 来加载新的VC 并加载新的webView

但是,webView 触发器上还有另一个谷歌地图链接,由以下 Classic ASP onclick 代码触发。

我如何检测何时在webView 上点击了这个谷歌地图链接?目前上述检测URL链接的方法无法检测到onclick

服务器经典 ASP

<div id="map" onclick="window.open('http://maps.google.com/maps?q=<%=sLat%>,<%=sLongi%>(<%=sFCName%>)', '_system');"></div>

目标 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

【问题讨论】:

    标签: ios objective-c webview asp-classic onclick


    【解决方案1】:

    查看this answer. 您遇到的问题是shouldStartLoadWithRequest: 没有在JavaScript window.open() 上被调用。链接上的答案有一种方法可以确保您的代码被调用。我在想一个委托方法会抓住这个,但现在我看不到它。也许我在想WKWebView

    【讨论】:

      【解决方案2】:
      - (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;
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-10-07
        • 1970-01-01
        • 2023-03-09
        • 1970-01-01
        • 1970-01-01
        • 2017-03-14
        • 2012-03-22
        • 2011-11-16
        相关资源
        最近更新 更多