18

I'm trying to invoke a function in a WebView. Some target functions I need to call are these:

play: function()
{
    if (this.value < this.p.max)
    {
        this.inc();
        this.timer = new it_timer({ object: this, method: "play", timeout: 200 });
    }
    else
        this.stop();
},
stop: function()
{
    if (this.timer)
        this.timer.stop();
    this.playing = false;
    this.playbutton.style.backgroundPosition = "0 0";
}

I started by calling

webView.InvokeScript("play", new string[0]);

but that didn't work, HRESULT: 0x80020101. I found this http://support.microsoft.com/kb/247784 on the topic, but it didn't help me at all.

I then tried to do what I found as an example on multiple sites:

webView.InvokeScript("eval", new string[] { "document.documentElement.outerHTML;");

and

webView.InvokeScript("alert", new string[] {"message"});

but both of those didn't work, giving the same HRESULT code. The WebView renders normally and javascript works fine on the page.

I'd appreciate any help in identifying the problem / finding a solution.

EDIT: It seems "alert" and all methods which are declared in classes don't work. There seems to have been an InvokeMethod(..) in earlier .NET Versions, are there any alternatives for WinRT?

SBoss
  • 8,845
  • 7
  • 28
  • 44
  • 1
    I'd also like to know this and would be very happy if someone can figure this out or poke at someone at Microsoft to answer this thing. – Akku Jun 14 '12 at 13:08

1 Answers1

30

That error occurs when you have a syntax error in the javascript, it appears.

Anthony Wieser
  • 4,351
  • 1
  • 23
  • 25
  • Thanks, and sorry for not marking it as an answer for so long. Didn't really help in my case, sadly, because I don't control the javascript. – SBoss Feb 22 '13 at 15:57
  • Thank you. This helped me. To be clear, this happens when there is runtime error too (in my case, using undeclared variable). – Luke Vo Apr 13 '18 at 11:02