OC js interaction (usually, if the page is written formally, it can be normal interaction, before the background write H5 never get the event, elements can not get, let alone interaction, it is odd strange)

Source: Internet
Author: User

Auto-populate forms

@" document.getElementById (' loginID '). Value = ' Fill in your username here ';d ocument.getelementbyid (' UserPassword '). Value = ' Fill in your password here '; ";
Enter the user name input box according to the ID and give the value according to the ID to enter the password input box and give the value

Automatically click the login button

@" document.getElementById (' login '). Click () "
Get the login button for this element based on the ID and call its Click event clicking ()

If there is a special limit, we need to visit a specific URL first and deposit a cookie

Nsurl * Cookiehost = [Nsurl urlwithstring:@"http://mmmmmm/login/Login.jsp"]; Nshttpcookie* Cookie =[Nshttpcookie cookiewithproperties: [nsdictionary Dictionarywithobjectsandkeys: [Cookiehost Host],nshttpcookiedomain, [Cookiehost Path],nshttpcookiepa Th,@"Cookie_name", Nshttpcookiename,@"Cookie_value", Nshttpcookievalue,nil]]; [[Nshttpcookiestorage Sharedhttpcookiestorage] setcookie:cookie];

Exit login in order to, without other interference, to clear the cookie

Nshttpcookiestorage * MyCookie = [Nshttpcookiestorage sharedhttpcookiestorage];      for inch [MyCookie cookies])    {[        [nshttpcookiestorage sharedhttpcookiestorage] deletecookie:cookie];    }             * Path = nshomedirectory ();     * FilePath = [path stringbyappendingpathcomponent:@ "/library/cookies/cookies.binarycookies " ];     * Manager = [Nsfilemanager Defaultmanager];    [Manager Removeitematpath:filepath Error:nil];

Initiate a request, with a cookie to request, disguised as a specific user-agent,referer, etc.

Nsurl * url = [Nsurl urlwithstring:@"http://mmmmm/login/Login.jsp"]; Nsmutableurlrequest* Request =[Nsmutableurlrequest Requestwithurl:url]; Nsarray* Cookies =[[Nshttpcookiestorage sharedhttpcookiestorage] cookies]; Nsdictionary* headers =[Nshttpcookie requestheaderfieldswithcookies:cookies]; [Request SetValue:@"mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) applewebkit/537.36 (khtml, like Gecko) chrome/54.0.2840.98 safari/537.36"Forhttpheaderfield:@"user-agent"]; [Request SetValue:@"http://mmmmmm"Forhttpheaderfield:@"Origin"]; [Request SetValue:@"http://mmmmm/login/Login.jsp"Forhttpheaderfield:@"Referer"]; [Request Sethttpmethod:@"GET"];    [Request Sethttpshouldhandlecookies:yes]; [Request Setallhttpheaderfields:headers];

If you want to access the URL in a specific network environment, you have to deal with the judgment, of course, in this case, only limited

NSString *ipstring = [self deviceipadress][@ "en1/ipv4"];     = ipstring? Ipstring: [Self deviceipadress][@ "en0/ipv4"];         if ([self canloadnetfrom:ipstring]) {        [Self.webview loadrequest:request];     Else {        [svprogresshud showerrorwithstatus:@ " Current network environment does not support login "];    }

Update: To switch between different account passwords, how to re-write the program? Here with Settings.bundle.

And just pick it up with your preference.

Nsuserdefaults *user = [Nsuserdefaults standarduserdefaults];     *accout = [user stringforkey:@ "name_preference"];     *PSD = [user stringforkey:@ "psd_preference"];

OC js interaction (usually, if the page is written formally, it can be normal interaction, before the background write H5 never get the event, elements can not get, let alone interaction, it is odd strange)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.