0

I use the following JavaScript code inside a WKWebView:

[webView evaluateJavaScript:@"document.getElementsByClassName('blog-background overlay text-center align-middle animated from-top animation-on')[0].style.display = 'NONE'" completionHandler:^(id _Nullable sha, NSError * _Nullable error) {
                NSLog(@"%@", error);

            }];

I get this error:

Error Domain=WKErrorDomain Code=4 "A JavaScript exception occurred" UserInfo={NSLocalizedDescription=A JavaScript exception occurred}

How can I solve the problem?

Casimir Crystal
  • 18,651
  • 14
  • 55
  • 76
Bison
  • 1
  • 1
  • first try this script in a browser or jsfiddle, with your html. figure out the reason for error there. – Nishant Feb 24 '16 at 06:51
  • I execute this JS code on the browser page can be hidden inside the corresponding element – Bison Feb 24 '16 at 06:55
  • Possible duplicate of [WKWebview evaluateJavascript is not working, throws an error](http://stackoverflow.com/questions/27849465/wkwebview-evaluatejavascript-is-not-working-throws-an-error) – Sujay Feb 24 '16 at 07:11

1 Answers1

0

may be because you are adding the javascript before the view complete load the content, Write your code in below delegate method and check what happens:

webView:didFinishNavigation:
Ronak Chaniyara
  • 5,125
  • 3
  • 21
  • 50
  • I was the operations performed in the method you said, this is hidden footView,And it delayed the execution of code 2 seconds before – Bison Feb 24 '16 at 06:57