In my webViewDidFinishLoad method inside the UIWebViewController I have been trying to separate javascript calls so that they will only be performed on certain URLS. So far I have been trying a simple if statement that takes the current URL and tries to match the two strings. This is however not allowing the if statement to run despite the urls matching. Any help would be appreciated.
NSString *currentURL = homePage.request.URL.absoluteString;
if (currentURL == @"www.google.com"){
NSLog(@"hi");
[webView stringByEvaluatingJavaScriptFromString:injectedEmail];
[webView stringByEvaluatingJavaScriptFromString:injectedPassword];
[homePage stringByEvaluatingJavaScriptFromString:@"var field = document.getElementById('loginSubmit');"
"document.forms[0].submit();"];
}
You should take a look at NSURL Class Reference, which will tell you that
-(NSString *)absoluteStringreturns an RFC 1808 absolute URL. These animals look likehttp://www.google.com/search?q=NSURL, and don’t have just a host name.Also, when you’re comparing strings in Objective-C, using
==will compare the string pointers, not the strings. You should be using something like:But you may not care about the complete
absoluteURL, in which case I would suggest: