Hyunjin Lee
Hyunjin Lee

Reputation: 143

How to detect when a Cordova WebView completely finished loading?

I have embedded cordova webview. and then I have called javascript from native like below.

  [self.viewView stringByEvaluatingJavaScriptFromString: jscode];

but it is not performing because JS files were not loaded.

How to detect when a Cordova WebView completely finished loading?

Upvotes: 0

Views: 1175

Answers (1)

jcesarmobile
jcesarmobile

Reputation: 53301

When the html is loaded, a notification is posted. You can listen to it with this code:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pageDidLoad) name:CDVPageDidLoadNotification object:self.webView];

Then, when the notification is received, the pageDidLoad method will be called, put your code there

- (void)pageDidLoad
{
    NSString * jscode = @"some js code here";
   [self.viewView stringByEvaluatingJavaScriptFromString: jscode];
}

Upvotes: 1

Related Questions