pavanbehere / open-webkit-sharp

Automatically exported from code.google.com/p/open-webkit-sharp
GNU Lesser General Public License v3.0
0 stars 0 forks source link

windowScriptObject not implemented #105

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. call the following from script:

using WebKit.Interop;
...

IWebView WebView = webKitBrowser1.WebView;
object arg = "hello";
object r;

r = WebView.windowScriptObject().callWebScriptMethod("window.alert", ref arg, 
1);

What is the expected output? What do you see instead?
I expect that an alert window displays with the message "Hello", instead I get 
an error: System.NotImplementedException: The method or operation is not 
implemented.

What version of the product are you using? On what operating system?
OpenWebKitSharp 2.8
VS.NET 2008 SP1, Windows XP SP3

Original issue reported on code.google.com by vbgu...@gmail.com on 5 May 2012 at 4:34

GoogleCodeExporter commented 8 years ago
Ok, I found a work around which only works with the .NET v4 of the component.  
Basically I need to put the code in the Navigated event as the objects get 
unloaded each time a new page is loaded.  Then, using the ScriptManager, I get 
a reference to the global script object.  Then a call SetProperty which 
attaches the .NET object to the script.  Once this is done, I am able to invoke 
the .NET object directly from script!

Code (.NET):

    public class TEST
    {
        public double Foo(double a)
        {
            a++;
            return a;
        }
    }

    ...

    private void webKitBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e)
    {
        JSObject o;
        o = webKitBrowser1.GetScriptManager.GlobalContext.GetGlobalObject();
        o.SetProperty("TEST", new TEST());
    }

Script (JS):
 <script type="text/javascript" language="javascript">
  <!--

   alert(TEST.Foo(1)); // Prints 2

  //-->
 </script>

Original comment by vbgu...@gmail.com on 9 May 2012 at 6:26

GoogleCodeExporter commented 8 years ago
windowScriptObject() is not implemented in WebKit but the alternative option is 
the one you stated in your 2nd post. Issue closed.

Original comment by tsumalis96@gmail.com on 10 May 2012 at 7:05