uiwebviewdelegate

UIWebView stringByEvaluatingJavaScriptFromString

ぐ巨炮叔叔 提交于 2019-11-28 23:15:25
问题 I'm stuck on getting some pretty basic JS to run in my UIWebView. In the web view's delegate, I have : - (void)webViewDidFinishLoad:(UIWebView *)wView { NSString *someHTML = [wView stringByEvaluatingJavaScriptFromString:@"document.getElementsByClassName('box')[0]"]; NSString *allHTML = [wView stringByEvaluatingJavaScriptFromString:@"document.body.innerHTML"]; NSLog(@"someHTML: %@", someHTML); NSLog(@"allHTML: %@", allHTML); } but when the method is invoked, someHTML is nil while allHTML

How to get HTTP headers

亡梦爱人 提交于 2019-11-28 22:19:36
问题 How do you retrieve all HTTP headers from a NSURLRequest in Objective-C? 回答1: This falls under the easy, but not obvious class of iPhone programming problems. Worthy of a quick post: The headers for an HTTP connection are included in the NSHTTPURLResponse class. If you have an NSHTTPURLResponse variable you can easily get the headers out as a NSDictionary by sending the allHeaderFields message. For synchronous requests — not recommended, because they block — it’s easy to populate an

How to disable long touch in UIWebView?

℡╲_俬逩灬. 提交于 2019-11-28 19:17:59
I want to disable long-touch from the application. I have no control on the HTML that I am loading on my WebView. In webViewDidFinishLoad delegate I run a javascript on the loaded html page that disable the long touch. [webView stringByEvaluatingJavaScriptFromString:@"document.body.style.webkitTouchCallout='none'; document.body.style.KhtmlUserSelect='none'"]; You could try to override the following methods from the view controller : - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event; - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event; - (void)touchesMoved:(NSSet *

How can I get a UIWebView to focus on a form input and bring up the keyboard?

若如初见. 提交于 2019-11-28 09:24:27
I've created a UIWebView for logging into Facebook's Graph API OAuth interface. This works great, but I have to tap the first input field in order for the keyboard to pop up. Ideally, the keyboard would appear as soon as the form appears. So I've been trying to figure out how to make the first form field get the focus from the webViewDidFinishLoad: UIWebViewDelegate method, like so: - (void)webViewDidFinishLoad:(UIWebView *)wv { [webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByName('email')[0].focus();"]; } Alas, this does not work. Curiously, when I run that JavaScript

Find text in webview page using swift?

旧时模样 提交于 2019-11-27 17:18:42
问题 How can I find text in uiwebview page and highlight it and go to its position in the page using swift ? For example chrome find text : search example But I'm using alert view instead : my search example in my app !!! 回答1: Here is the swift code: 1) add UIWebViewSearch.js file to your project func highlightAllOccurencesOfString(str:String) -> Int { let path = Bundle.main.path(forResource: "UIWebViewSearch", ofType: "js") var jsCode = "" do{ jsCode = try String(contentsOfFile: path!) }catch { /

How to handle app URLs in a UIWebView?

社会主义新天地 提交于 2019-11-27 16:56:58
I recently found that my UIWebView was choking on ITMS links. Specifically, from the UIWebView in my app, if I navigate to a site such as this one and click the "Available on the App Store" link, UIWebView would error out with "Error Domain=WebKitErrorDomain Code=101 The URL can't be shown." After a bit of Googling, I realized that I needed to catch requests for app links and have iOS handle them. I started out by looking to see if the scheme starts with "itms" in -webView:shouldStartLoadWithRequest:navigationType: , but realized that there might be other kinds of app links that the system can

How to disable long touch in UIWebView?

烂漫一生 提交于 2019-11-27 12:12:42
问题 I want to disable long-touch from the application. I have no control on the HTML that I am loading on my WebView. 回答1: In webViewDidFinishLoad delegate I run a javascript on the loaded html page that disable the long touch. [webView stringByEvaluatingJavaScriptFromString:@"document.body.style.webkitTouchCallout='none'; document.body.style.KhtmlUserSelect='none'"]; 回答2: You could try to override the following methods from the view controller : - (void)touchesBegan:(NSSet *)touches withEvent:

How can I get a UIWebView to focus on a form input and bring up the keyboard?

假装没事ソ 提交于 2019-11-27 02:59:40
问题 I've created a UIWebView for logging into Facebook's Graph API OAuth interface. This works great, but I have to tap the first input field in order for the keyboard to pop up. Ideally, the keyboard would appear as soon as the form appears. So I've been trying to figure out how to make the first form field get the focus from the webViewDidFinishLoad: UIWebViewDelegate method, like so: - (void)webViewDidFinishLoad:(UIWebView *)wv { [webView stringByEvaluatingJavaScriptFromString:@"document

NSString in UIWebview

浪尽此生 提交于 2019-11-27 00:45:03
I have an NSString and a webView in my project (Objective-C for iPhone), I have called index.html in webView and inside it I inserted my script (javascript). How can I pass the NSString as a var in my script and viceversa? This is an example , but I don't understand it very well. Michael Kessler Send string to web view: [webView stringByEvaluatingJavaScriptFromString:@"YOUR_JS_CODE_GOES_HERE"]; Send string from web view to Obj-C: Declare that you implement the UIWebViewDelegate protocol (inside the .h file): @interface MyViewController : UIViewController <UIWebViewDelegate> { // your class

How to delete all cookies of UIWebView?

北城余情 提交于 2019-11-26 19:31:02
In my application, I have a UIWebview that loads linkedin auth page for login. When user logs in, cookies saves into the application. My app has a logout button that is not related to linkedin login. So when user clicks on this button, he logs off from the app. I want that this log off will clear his linkedin cookies also from the app, so that user will log out completely. Sergio Moura According to this question , you can go through each cookie in the "Cookie Jar" and delete them, like so: NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage]; for (NSHTTPCookie *cookie