stringbyevaluatingjavascr

WkWebView Evaluatejavascript returns unsupported type error

一个人想着一个人 提交于 2020-07-18 04:33:48
问题 I'm sending a value to javascript function and get a result. However, I'm getting "Error Domain=WKErrorDomain Code=5 "JavaScript execution returned a result of an unsupported type" UserInfo={NSLocalizedDescription=JavaScript execution returned a result of an unsupported type}" error when run below code; webView?.evaluateJavaScript("getURL()") { (result, error) in if let error = error { print("\(error)"); return } if let song = result as? String { print("\(song)"); } } and javascript code as

Get Attribute From Multiple Div Elements into my iOS app from UIWebView W/Swift

人走茶凉 提交于 2019-12-08 10:42:12
问题 How do I get an attribute from a div element defined in my UIWebView into my iOS app? To explain further... I have a very simple html document that I load into a UIWebView. It allows a user to click to turn buttons on or off. I set an attribute on the divs to true or false. Refer to my code below. <html> <head> <title>Tire Selection Template</title> <style> .front_truck_box{ display:flex; flex-wrap: wrap; border:1px solid black; height:80px; flex: 0 1 80px; padding:10px; } .middle_truck_box,

load local image into UIWebView

半腔热情 提交于 2019-12-06 14:42:49
问题 I want to take a screenshot and then send to webview a local path for it, so it will show it. I know that webview could take images from NSBundle but this screenshots are created dynamically - can I add something to it by code? I was trying it like this: UIGraphicsBeginImageContext( webView.bounds.size); [self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); NSString *file = @"myfile.png";

Is it possible to use stringByEvaluatingJavaScriptFromString with Javascript which references local files?

爱⌒轻易说出口 提交于 2019-12-05 06:47:53
问题 I want to use stringByEvaluatingJavaScriptFromString to run a javascript which references local files (in this case css files, but potentially js files too) which are on the device (in the Documents folder I guess?)... NSString *theJS = [[NSString alloc] initWithString:@"javascript:(function() {the_css.rel='stylesheet'; the_css.href='the_css.css'; the_css.type='text/css'; the_css.media='screen';} )();"]; [webView stringByEvaluatingJavaScriptFromString:theJS]; How would I get this to work? It

load local image into UIWebView

依然范特西╮ 提交于 2019-12-04 19:12:16
I want to take a screenshot and then send to webview a local path for it, so it will show it. I know that webview could take images from NSBundle but this screenshots are created dynamically - can I add something to it by code? I was trying it like this: UIGraphicsBeginImageContext( webView.bounds.size); [self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); NSString *file = @"myfile.png"; NSString *directory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES)

Is it possible to use stringByEvaluatingJavaScriptFromString with Javascript which references local files?

血红的双手。 提交于 2019-12-03 22:22:33
I want to use stringByEvaluatingJavaScriptFromString to run a javascript which references local files (in this case css files, but potentially js files too) which are on the device (in the Documents folder I guess?)... NSString *theJS = [[NSString alloc] initWithString:@"javascript:(function() {the_css.rel='stylesheet'; the_css.href='the_css.css'; the_css.type='text/css'; the_css.media='screen';} )();"]; [webView stringByEvaluatingJavaScriptFromString:theJS]; How would I get this to work? It works fine if I use an external css file, like the_css.href='http://www.website.com/the_css.css'; What