Check if Javascript function exists on webpage before calling ExternalCall

I want to do something like this:

if (/*Check if FunctionOnWebpage exists*/) {
	Application.ExternalCall("FunctionOnWebpage", args);
}

Right now I get an exception if the web page does not contain the function I’m trying to call from Unity. Wrapping it in a try/catch block doesn’t work.

Try something like this. It will check if FunctionOnWebpage exists, and if it does, call FunctionOnWebpageExists in Unity on a GameObject named “MyGameObject”.

Application.ExternalEval("if (typeof FunctionOnWebpage == 'function'){SendMessage('MyGameObject', 'FunctionOnWebpageExists');}");

Then you can make FunctionOnWebpageExists call

public void FunctionOnWebpageExists () {
	Application.ExternalCall("FunctionOnWebpage", args);
}