WebView callback in javascript

WebView callback in javascript


I’m trying to get callbacks registered for WebViews in javascript. All the examples I find are in C++ but cc_callback doesn’t work in javascript. I can open the url but the callbacks keep saying “({}) is not a function”. I need to do two things. Set these callbacks:

  1. setOnDidFinishLoading
  2. setOnShouldStartLoading
  3. setOnDidFailLoading

I also need to be able to read the url on redirects in setOnShouldStartLoading.

My code is below:
this.webViewShouldStartLoading = function() {
cc.log("url should start loading " + webViewUrl);
return true;

this.webViewDidFinishLoading = function() {
cc.log("url finished loading " + webViewUrl);

this.webViewDidFailLoading = function() {
cc.log("url failed loading " + webViewUrl);

And I set the callback with:
this.webView.setOnDidFinishLoading(cc.CallFunc.create(this.webViewDidFinishLoading, this));

Any thoughts?