【问题标题】:Detecting POST Method/Button click UIWebView检测 POST 方法/按钮单击 UIWebView
【发布时间】:2017-04-26 12:10:58
【问题描述】:

我正在尝试在这里处理一个点击按钮: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

还有其他方法吗?

【问题讨论】:

    标签: ios swift uiwebview


    【解决方案1】:

    我无法通过您的问题判断您是尝试提交表单还是观察何时提交。但是,如果您尝试提交表单,则可以这样做。

    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/,但情况似乎并非如此。

    【讨论】:

    • 嘿,我正在尝试观察而不是提交。正如你所说,链接没有被调用,这很奇怪。有任何想法吗 ?无论如何,谢谢你的回答!
    • 对web表单了解不多,但是好像点击按钮的时候是网页在做post请求,而不是浏览器。所以没有加载新的 URL。我玩过 UIWebView 委托,但没有一个被调用。因此,除非您的网页更改为加载帖子 URL,否则我认为 UIWebView 不够复杂,无法满足您的需求。
    • 是的,我也得出了这个结论...非常感谢!
    猜你喜欢
    • 1970-01-01
    • 2011-01-22
    • 2019-02-28
    • 2012-10-16
    • 2019-12-23
    • 1970-01-01
    • 1970-01-01
    • 2020-02-08
    • 2015-11-06
    相关资源
    最近更新 更多