0

I need to inject a js file with a class into WebBrowser element for WP7 application, but I get an unknown runtime error:

 webbrowser.InvokeScript("eval", "function Player() {  this.play = function(e) { window.external.notify(e); }}

Is this possible?

5
  • 1
    Describe your error. You can find it in your IDE. I once encountered with a js inject error because I tried to inject it before the webbrowser is ready. Be sure to place your code in the webbrowser's documentReady() callback Commented Jun 3, 2013 at 11:05
  • There is no documentReady() callback in Windows Phone WebBrowser, but the error seems to be gone when I put this code into Navigated callback. There are no errors now. But it is not working... Commented Jun 3, 2013 at 11:11
  • Duplicate: How to inject Javascript in WebBrowser control? Commented Jun 3, 2013 at 11:34
  • I have to confess I haven't tried WP. However things are similar with c# winform. And Navigated() is called after successfully loading the document. Commented Jun 3, 2013 at 13:54
  • Alla Masoud, it is not a duplicate. This problem is more specific than the one you've pointed out. Commented Jun 3, 2013 at 16:26

1 Answer 1

1

I just encountered this myself.

The problem is that you are not sending in the parameter as a string. eval takes a string as parameter and if you invoke this script with your current parameter it will translate into:

eval(function Player() {  this.play = function(e) { window.external.notify(e); }})

when what you really want to do is:

eval("function Player() {  this.play = function(e) { window.external.notify(e); }}")

So the correct this, try:

webbrowser.InvokeScript("eval", "\"function Player() {  this.play = function(e) { window.external.notify(e); }}\"");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.