开发者

How do I check if a WebView is loading a specific page?

I want check if my WebView is loading a specific html page locally (for example index2.html). Is that possible? Thanks!!

EDIT:

I have used this code:

NSString *currentURL
    = webview1.request.URL.absoluteString;

    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"indexPRO" ofType:@"html"];

    urlLocation1 = [NSURL fileURLWithPath:filePath];

    if(currentURL = urlLocation1){ //Do something..

but not work.... Is because I 开发者_如何学编程use "absolute string" in currentURL and relative string in "urlLocation1"??


Look at UIWebView delegate methods

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {

// examine request to see what url is about to load.
// return YES to allow the load, NO to disallow.
// don't forget to set the delegate:
// myWebView.delegate = self;

    return YES;
}

one of webViewDidFinishLoad or webView:didFailLoadWithError will be called when the request is completed. and as mentioned, checking the "loading" property of your UIWebView object will indicate if something is still be loaded.

if( myWebView.loading ) ...

EDIT: in response to your additional information, (assuming I understand what you're trying to do...) try the following:

// compare scheme property of URL against "file"
if( [[webview1.request.URL scheme] isEqualToString:@"file"] ){
    NSLog(@"load request is local file");
    // ... your code here ...
}

I don't know whether a UIWebView "request" property is valid once the load is finished, haven't tested that. If not, keep a private copy of the most recently loaded URL or request somewhere else.


You can check its "loading" property to see whether it's done or not. You can check the "request" property to get the NSURLReqest to see what it's loading or has loaded.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜