2

I have an aspx page on my webserver which I load through an embedded web browser on a windows form. I am able to call the Sub1 from javascript window.external procedure. This is only when using the standard VB control WebBrowser. I have the necessary permissions active with

<PermissionSet(SecurityAction.Demand, Name:="FullTrust")> _
<System.Runtime.InteropServices.ComVisibleAttribute(True)> _

This works just fine. However, I am in need of using GeckoFx as my javascript is too complex for the standard WebBrowser as well as my styling. I have tried the same approach as is, just with the geckobrowser, but it does not work at all, is there any:

GeckoPrefereces.User("somesetting") = True

that I need to activate to get it to work or is there something else I am missing?

I would just like to call the 'form close' procedure of my windows form, from the webpage which is embedded in the GeckoBrowserControl.

dav_i
  • 27,509
  • 17
  • 104
  • 136
Killua
  • 92
  • 10

1 Answers1

2

Refer the following link for your answer as it is solved here. How to call C# method in javascript by using GeckoFX as the wrapper of XULRunner

Change this process to C# as VB cannot send the message to a procedure, only store the value and this creates a difficult situation in reading the data later.

then:

private void showMessage(string s)
{
   if (s == "some data") 
   {
       //Do stuff here you need to, ie. close the form, etc
   }
}

This allows you to read the message sent and do with it what you wish. Also important:

browser.AddMessageEventListener("myFunction", ((string s) => this.showMessage(s)));

must be before you load the html or the url

myBrowser.Navigate("www.google.com");
Community
  • 1
  • 1
LieBieS
  • 141
  • 3
  • Are you saying that VB just flat out can't receive messages from JS when using geckofx? So if we're using geckofx in a VB project, and we have a bunch of window.external calls in js, that we need to convert the VB file to C#? Say it ain't so!! – whyoz Feb 26 '15 at 02:31
  • 1
    The C# conversion of ' => this.showMessage(s) ', I have not been able to replicate in VB, the errors keep saying the s cannot be assigned a value. The only way I found around it was adding the C# as a project to the VB solution as a whole, the C# project must compile as a class, then added as a reference to the VB project. Then it may be called from VB to open the C# winform with the Geckofxbrowser on it there. This method solved my problem as I gave up trying to get it to work in VB. – Killua Feb 26 '15 at 08:49
  • @Killua and anyone else interested, voting up supporting ObjectForScripting in geckofx can be found here: http://tinyurl.com/pqrkg3y ... seems like this would be a great addition to geckofx to compete with other Chrome engines that do have support and docs for two way comms with .NET – whyoz Feb 26 '15 at 18:02