UIWebView Tips
URL
Get current URL using JavaScript
UIWebView+URL.h
#import <UIKit/UIKit.h> @interface UIWebView (URL) @property (nonatomic, readonly) NSString *URLString; @property (nonatomic, readonly) NSURL *URL; @end
UIWebView+URL.m
#import "UIWebView+URL.h" @implementation UIWebView (URL) - (NSString *)URLString { return [self stringByEvaluatingJavaScriptFromString:@"document.URL"]; } - (NSURL *)URL { return [NSURL URLWithString:self.URLString]; } @end
Display about:blank
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"about:blank"]]];
Delete Cookie
NSHTTPCookieStorage *cookieStrage = [NSHTTPCookieStorage sharedHTTPCookieStorage]; for (id obj in [cookieStrage cookies]) { [cookieStrage deleteCookie:obj]; }
Clear Cache
NSURLCache *cache = [NSURLCache sharedURLCache]; [cache removeAllCachedResponses];
timeout
timeout setting is from NSURLRequest not UIWebView.