ios 怎样获取当前web的url
发布网友
发布时间:2022-10-08 11:27
我来回答
共1个回答
热心网友
时间:2023-11-09 14:40
[objc]
@property (strong,nonatomic)UIWebView *webView;
@property (strong,nonatomic)NSString *currentURL;
@property (strong,nonatomic)NSString *currentTitle;
@property (strong,nonatomic)NSString *currentHTML;
[objc] view plaincopy
---------------------------------
[objc]
[objc]
-(void) webViewDidFinishLoad:(UIWebView *)webView {
[UIApplicationsharedApplication].networkActivityIndicatorVisible =NO;
self.title = [webViewstringByEvaluatingJavaScriptFromString:@"document.title"];//获取当前页面的title
self.currentURL = webView.request.URL.absoluteString;
NSLog(@"title-%@--url-%@--",self.title,self.currentURL);
NSString *lJs = @"document.documentElement.innerHTML";//获取当前网页的html
self.currentHTML = [webView stringByEvaluatingJavaScriptFromString:lJs];
}