locked
InvokeScriptAsync() with arguments

    Question

  • Hi,

    How to use InvokeAsyncMethod() to call a JS method with input parameters passed on ?

    Can someone provide an example for the same ?

    using create task i can call it like this without arguments WebView->InvokeAsyncMethod(L"functioname",{})

    But how to do the same if i want to send some data to the script (like lets say "A":hello, "B"; Hi).

    thanks !!


    Saturday, April 26, 2014 8:50 AM

All replies

  • Hi Minu7:

    This works for me. Please excuse the code formatting. This edit window doesn't behave as I would expect.

    String^ html = ref new String(LR"delimit(<html><head><script type='text/javascript'>function SayGoodbye(name) {

    document.getElementById('myDiv').innerText = 'GoodBye  ' + name;}

    </script></head><body><div id='myDiv'>Hello</div></body></html>)delimit");

    viewer->NavigateToString(html);


    ...

    //LoadCompleted event handler looks like this

     
    void App2::MainPage::viewer_LoadCompleted(Platform::Object^ sender, Windows::UI::Xaml::Navigation::NavigationEventArgs^ e)

    {

    auto MyArgs = ref new Platform::Collections::Vector<String^>();
    MyArgs->Append("Minu");
    create_task(viewer->InvokeScriptAsync(L"SayGoodbye", MyArgs));

    }

    Hope this helps!


    Sunday, April 27, 2014 7:49 PM
  • Hi,

    this helps. Thank you.. This Async Operation returns a string correct ?

    Is there a way to debug the flow specially while using webview. I have a webview which navigates to a page, and while the javascript loads, i have a InvokeScriptAsync() call from native code, but something is getting stuck and i'm repeatedly getting caught with exceptions.

    Can you please help me on this ?

    Thanks !!

    Thursday, May 1, 2014 11:27 AM