-1

How to use following javascript code in Objective-C ?

var theFormId = $('form').filter(function() {
return this.innerHTML.indexOf('forgot your password') != -1;
}).attr('id');

HOw to use code above in UIWebView's stringByEvaluatingJavaScriptFromString: method ?

I used the code above with Objective-C as follows:

NSString *formID = [NSString stringWithFormat:@"%@",[self.browser stringByEvaluatingJavaScriptFromString:@"$('form').filter (function() {var text = this.innerHTML.toLowerCase();" 
                        "return text.indexOf('forgot your password') != -1 || "
                        "text.indexOf('remember me') != -1;}).attr('id');"] ];

When trying to log formID , it prints nothing. Is there any syntax error in my code ?

  • Please refer to the related question [here][1] this will help you a lot [1]: http://stackoverflow.com/questions/766627/uiwebview-stringbyevaluatingjavascriptfromstring-not-changing-text-box-value – The iOSDev Apr 09 '12 at 08:09
  • 1
    @AalokParikh to use links in comments you need to use this format `[text](http://URL)` – Ben Brocka Apr 10 '12 at 14:44

1 Answers1

2

I have no idea if this will work because you have only given a very small part of your problem.

Firstly, your Javascript doesn't look like it is valid. I suspect it should be:

var theFormId = $('form').filter(function() {
    var text = this.innerHTML.toLowerCase(); 

    return text.indexOf('forgot your password') != -1 || 
           text.indexOf('remember me') != -1;
});

I added some closing brackets.

To run this Javascript using -stringByEvaluatingJavaScriptFromString: you would do something like the following.

NSString *javascript = @"var theFormId = $('form').filter(function() { var text = this.innerHTML.toLowerCase(); return text.indexOf('forgot your password') != -1 || text.indexOf('remember me') != -1; });";

NSString *result = [webView stringByEvaluatingJavaScriptFromString:javascript];

I'm not sure what you'll get in the result string when you run this though.

mttrb
  • 8,297
  • 3
  • 35
  • 57
  • Please to go to my original question at here : http://stackoverflow.com/questions/10069564/finding-the-login-form-based-on-content – Manish Verma Apr 09 '12 at 08:54