Hi,
I'm using a webview and while the content renders we have our associated JS files loaded.
We receive external notifications from JavaSCript to native app code but on the other hand, we are unable to invoke a script that is contained outside.
Please see below example
String ^ htmlFragment = L"<!DOCTYPE html>\n" +
"<html>\n" +
" <head>\n" +
" <script type = 'text/javascript'>\n" +
" function onResponse(){ \n" +
//"var response = JSON.parse(jsonResponse); \n" +
//" var callback = response.context; \n" +
"document.getElementById('myDiv').innerText = 'called form onresponse'; \n" +
"return 'hey you'; \n"
" }\n" +
" doSomething: function(str) {\n" +
" document.getElementById('myDiv').innerText = str;\n" +
" return 'Hello World!';\n" +
" }\n" +
" </script>\n" +
" </head>\n" +
" <body>\n" +
" <div id = 'myDiv'>Hello</div>\n" +
" </body>\n" +
"</html>\n";
There is an anonymous function defined in the above script. The property doSomething's value will be set by this function call.
Now, when i try to invoke this method "onResponse", it throws an exception stating "unknown name"
create_task(webView5->InvokeScriptAsync(L"onResponse", nullptr)).then([this](String ^result)
{
Platform::Details::Console::WriteLine(L"Result from script " + result);
});
If i remove this chunk (anonymous function) from the above html/JS code, it works ( i mean OnResponse method is called).
So, why is InvokeScriptAsync() crashing when we have properties and their values defined in the form of anonymous function names ?
How do we invoke scripts in such a case because we have various properties and their values set through function return values in our case ?
Can someone please immediately help on this or throw some light on how this API works ?
Thanks !!