iOS Objective C - UIWebView AutoFill and Execute

前端 未结 1 738
再見小時候
再見小時候 2020-12-29 16:45

I was wondering is there any possible way that I can have a webview that automatically inputs the values for text boxes on a website and submit so that the user can just byp

相关标签:
1条回答
  • Yes, you can use the following javascript to fill out the form then submit it.

    //Set the values
    NSString* firstValue = @"first value here";
    NSString* secondValue = @"second value here";
    // write javascript code in a string
    NSString* javaScriptString = @"document.getElementById('nameOfOneInput').value=%@;"
    "document.getElementById('nameOfAnotherInput').value=%@;"
    "document.forms['nameOfForm'].submit();";
    
    // insert string values into javascript
    javaScriptString = [NSString stringWithFormat: javascriptString, firstValue, secondValue];
    
    // run javascript in webview:
    [webView stringByEvaluatingJavaScriptFromString: javaScriptString];
    

    You obviously have to set firstValue and secondValue first.

    0 讨论(0)
提交回复
热议问题