简体   繁体   中英

I want my program to detect when the user clicks submit button on a website via uiwebview (iphone)

I want to detect when the user click on submit button (after entering username and password) on the website via my uiwebview. I need to detect this action in order to retrieve the cookies from the logged in version of the webpage right after the user information is submitted.

I think this detecting thing involves setting delegate for the webview and writing some javascript operation via objective-c. I am not sure though.

How would you solve this problem? Any help is much appreciated!

Here is the part of the code for the webpage:

<form id="login-email" class="badge-login-form" action="https://9gag.com/login" method="POST">
    <input type="hidden" id="jsid-login-form-csrftoken" name="csrftoken" value="999d68db0f5ed15d8966b66f23a52c3b"/>
    <input type="hidden" id="jsid-login-form-next-url" name="next" value=""/>
                            <input type="hidden" name="location" value="1"/>
                    <p class="lead">Log in with your email address </p>
    <div class="field">
        <label for="jsid-login-email-name">Email</label>
        <input id="jsid-login-email-name" type="text" name="username" value="" autofocus="autofocus"/>
    </div>
    <div class="field">
        <label for="login-email-password">Password</label>
        <input id="login-email-password" type="password" name="password" value="" />
                </div>
    <div class="btn-container">
        <input type="submit" value="Log in" onclick="GAG.GA.track('login-signup', 'login', 'login-form');"/>

If you set yourself as the delegate of the UIWebView, you can implement the method:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    NSURL *url = request.URL;
    // this is the url you are about to load

    return YES;
}

If you use separate forms for each set of inputs, you can use 'onsubmit='

<form onsubmit="your_function_here "id="login-email" ... >

and if the user clicks submit or presses enter, your_function will be invoked

Just an idea, hope it helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM