【问题标题】:Get current URL in UIWebview but it not respond在 UIWebview 中获取当前 URL 但它没有响应
【发布时间】:2023-03-02 22:15:01
【问题描述】:

如果触摸 UIWebview 中的内容,我创建应用程序以使用 UIWebview 并将日志显示到 url。 这是我的代码

- (void)viewDidLoad {
    [super viewDidLoad];
    NSURL *url1 =[NSURL URLWithString:@"MyWebSite"];
    NSURLRequest *request1 = [NSURLRequest requestWithURL:url1];
    [_webView1 loadRequest:request1];
    NSURL *url2 =[NSURL URLWithString:@"MyWebsite2"];
    NSURLRequest *request2 = [NSURLRequest requestWithURL:url2];
    [_webView2 loadRequest:request2];//url menu 2
    NSString *currentURL = [_webView1 stringByEvaluatingJavaScriptFromString:@"document.title"];
    NSLog(@"%@",currentURL);
}

但我触摸内容日志不打印并且更改 webview 日志打印 (null) 对不起我的英语不好。

【问题讨论】:

    标签: ios objective-c cocoa-touch uiwebview


    【解决方案1】:

    在从 URL 接收数据之前,您无法获取网站的标题。

    所以

    • 将您的webview delegate 设置为self

    然后在

    • - webViewDidFinishLoad:获取标题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-01-30
      • 2011-07-31
      • 2019-05-20
      • 1970-01-01
      • 1970-01-01
      • 2011-06-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多