Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
48
rated 0 times [  52] [ 4]  / answers: 1 / hits: 29184  / 10 Years ago, thu, january 8, 2015, 12:00:00

I am trying to call an existent function from a remote site in a WKWebview:



function addtext (text) {
jQuery(#webviewtest).html(text);
}


With:



[self.WebView evaluateJavaScript:@addtext(This is a text from app); completionHandler:^(id Result, NSError * error) {
NSLog(@Error -> %@, error);
}];


But this is throwing an error:



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


This is so simple! I am must missing something really stupid!


More From » ios

 Answers
3

Found a solution, it was simple as I was expecting, I was adding the javascript before the view complete load the content (before the Dom Ready). So I just had to move my code to the delegate method below:





I hope this helps someone.


[#68274] Tuesday, January 6, 2015, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
brendaw

Total Points: 508
Total Questions: 90
Total Answers: 100

Location: Maldives
Member since Sat, Jan 29, 2022
2 Years ago
;