检测POST方法/按钮单击UIWebView

时间:2017-04-25 20:19:05

标签: ios swift uiwebview

我试图在此处理点击按钮:Link button 这是代码:

<form action="/contest-voting/" method="post" id="pimp-entities-contest-voting-form" accept-charset="UTF-8"><div><input type="hidden" name="nid" value="1200">

<input type="hidden" name="fb_id" value="">

<input type="hidden" name="form_build_id" value="form-iZa3h_R56jG3BZpQCaktyWo8exlP8PnURETJEm0omUk">

<input type="hidden" name="form_id" value="pimp_entities_contest_voting_form">
Nutze deinen <input type="image" id="edit-facebook" name="facebook" value="Per Facebook abstimmen" src="http://www.pimp-your-school.de/sites/all/themes/pimp_foundation/images/icon-voting-fb.png" class="form-submit">-Account oder deine <div class="form-item form-type-textfield form-item-email">

<input placeholder="E-Mail-Adresse" type="text" id="edit-email" name="email" value="" size="60" maxlength="128" class="form-text">

<input type="image" id="edit-submit" name="submit" value="Per E-Mail-Adresse abstimmen" src="http://www.pimp-your-school.de/sites/all/themes/pimp_foundation/images/icon-voting-3.png" class="form-submit"></div></form>

我已经尝试了所有不起作用的StackOverflow链接:

Identify submit button click of UIWebview

Grabbing POST data from UIWebView

UIWebView capture post

Swift UIWebView shouldStartLoadWithRequest doesn't fire in iOS8

Call swift function with javascript using UIWebview

还有其他方法吗?

1 个答案:

答案 0 :(得分:0)

我无法通过您的问题告诉您是否正在尝试提交表单或观察提交时间。但是,如果您尝试提交表单,则可以执行此操作。

func webViewDidFinishLoad(_ webView: UIWebView) {

    // This adds an email to the email text field. This takes the id of the email text field.
    webView.stringByEvaluatingJavaScript(from: "document.getElementById('edit-email').value = \"example@example.com\"")

    // This submits the field. This takes the id of the form.
    webView.stringByEvaluatingJavaScript(from: "document.getElementById('pimp-entities-contest-voting-form').submit()")

}

我不确定如何观察提交的表单,因为

func webViewDidStartLoad(_ webView: UIWebView)
提交表单时似乎没有调用

,因为通常,当url更改时,您将使用此函数。它应该更改为http://www.pimp-your-school.de/contest-voting/,但似乎并非如此。