Am loading a URL on a UIWebView at the viewDidLoad.
- (void)viewDidLoad
{
[super viewDidLoad];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL
URLWithString:@"http://abc.com/Test.html"]]];
}
Then on an NSTimer I run a the following to execute the javascript. The call to the JavaScript works well.
-(void)WebViewLoad:(NSTimer *)theTimer
{
NSString *abcFiles = [webView stringByEvaluatingJavaScriptFromString:@"abc.length"];
NSLog(@"The TotalNumberOfFiles is %i",abcFiles); //This works
//--------------------------------------------------------
NSString *currentURL = webView.request.URL.absoluteString;
NSLog(@"Current url 1 is %@",currentURL);
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://abc.com/newpage.html"]]];
[self.view addSubview:webView];
NSString *currentURL2 = webView.request.URL.absoluteString;
NSLog(@"Current url 2 is %@",currentURL2);
}
Everything above the commented line works. But the part where the new URL is added, I still get the initial URL. I tried adding reload. It did not work. Tried creating a new UIWebView object that too did not work.
Result is
Current url 1 is http: //abc.com/Test.html
Current url 2 is http: //abc.com/Test.html
I want
Current url 1 is http: //abc.com/Test.html
Current url 2 is http: //abc.com/newpage.html
Another question is that "can we load a new URL from the code. Its not coming via a button or any action. Its coming from a recurring timer. Is that an issue?"