Finding and auto-filling HTML login forms in a UIWebView using JavaScript

前端 未结 4 1339
自闭症患者
自闭症患者 2020-12-24 09:30

i have a UIWebView which acts like an internet browser and loads the HTML of the webpages that it is at.

in the webViewController, the method webViewDidFinishLoad, w

4条回答
  •  臣服心动
    2020-12-24 09:56

    I don't think finding a reference to the input elements will be difficult using javascript, but it's amending them that is not straightforward with the UIWebView.

    A hacky way to achieve what you want in the way you describe could be done by getting the HTML from the UIWebView, amending it, then loading it back in. E.g.:

    // Get the HTML from the UIWebView
    NSMutableString *html = [[[self.webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.outerHTML;"] mutableCopy] autorelease];
    
    // Find the range of the first input element.
    NSRange firstInputRange = [html rangeOfString:@"

提交回复
热议问题