Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Webbrowser control + com visable functions

Webbrowser control + com visable functions

Scheduled Pinned Locked Moved C#
comcsharpvisual-studiotoolsxml
11 Posts 3 Posters 12 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Spacix One
    wrote on last edited by
    #1

    I have an application where I use the web browser control and allow JScript to interact with my application though the object for scripting class that is set to com visible. I've been looking around the and I can't seem to find the limits of what data types/object you can pass to and from JScript. I know the basics work like int, float, string, ect... But I'd like to pass XML directly, but not as text due to the overhead of phrasing it. So does anyone know the limits or where to find out more information about the C# to JScript COM interop though the web browser control? I know the following works:

    public string feedJScriptXML()
    {
    //I know this example method is pointless, but it is just an example. The actual program sends XML it builds from other values
    XmlDocument myXMLDoc = new XmlDocument();
    myXMLDoc.Load("C:\myXMLfile.xml");
    return myXMLDoc.OuterXml;
    }

    Then send it as text to JScript and use it in JScript by

    function readCsharpXML()
    {
    var xmlString = window.external.feedJScriptXML();
    var theXML = new ActiveXObject("Microsoft.XMLDOM");
    theXML.load(xmlString);
    }

    The above is 100x better than writing the XML to a file and then reading the file into JScript... I think it might be better if I could dump the XML document into the JScript directly to save the extra phrase time... This application needs to read the XML 100's of times a minute so every little bit helps... The only information I've found on this is very basic via the MSDN C# tutorials http://msdn2.microsoft.com/en-us/vcsharp/bb798044.aspx?wt.slv=RightRail[^] and the WebBrowser.ObjectForScripting information at MSDN: http://msdn2.microsoft.com/en-us/library/system.windows.forms.webbrowser.objectforscripting(VS.80).aspx[^]


    -Spacix All your skynet questions[

    L N 2 Replies Last reply
    0
    • S Spacix One

      I have an application where I use the web browser control and allow JScript to interact with my application though the object for scripting class that is set to com visible. I've been looking around the and I can't seem to find the limits of what data types/object you can pass to and from JScript. I know the basics work like int, float, string, ect... But I'd like to pass XML directly, but not as text due to the overhead of phrasing it. So does anyone know the limits or where to find out more information about the C# to JScript COM interop though the web browser control? I know the following works:

      public string feedJScriptXML()
      {
      //I know this example method is pointless, but it is just an example. The actual program sends XML it builds from other values
      XmlDocument myXMLDoc = new XmlDocument();
      myXMLDoc.Load("C:\myXMLfile.xml");
      return myXMLDoc.OuterXml;
      }

      Then send it as text to JScript and use it in JScript by

      function readCsharpXML()
      {
      var xmlString = window.external.feedJScriptXML();
      var theXML = new ActiveXObject("Microsoft.XMLDOM");
      theXML.load(xmlString);
      }

      The above is 100x better than writing the XML to a file and then reading the file into JScript... I think it might be better if I could dump the XML document into the JScript directly to save the extra phrase time... This application needs to read the XML 100's of times a minute so every little bit helps... The only information I've found on this is very basic via the MSDN C# tutorials http://msdn2.microsoft.com/en-us/vcsharp/bb798044.aspx?wt.slv=RightRail[^] and the WebBrowser.ObjectForScripting information at MSDN: http://msdn2.microsoft.com/en-us/library/system.windows.forms.webbrowser.objectforscripting(VS.80).aspx[^]


      -Spacix All your skynet questions[

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #2

      I doubt you can return a .NET XmlDocument to Javascript but you might be able to return an MSXML interface. Of course then you don't have the simplicity of using XmlDocument in your C# code so I don't know if that is of any benefit.

      SpacixOne wrote:

      but not as text due to the overhead of phrasing it.

      you mean parsing it I guess. Are you sure the overhead is significant to warrant consideration? Also I have no idea what you are going to do with it in the javascript but I seems likely you want to copy some values from the XML into HTML elements for display etc. Can't you just do that using the DHTML interface from the C# code directly? Also when it comes to altering a HTML display in an embedded browser control you can generate the HTML using XML/XSLT transformation and then use one DHTML call to transfer the results into the browser document rather than using DHTML to access each discrete HTML element.

      led mike

      S 1 Reply Last reply
      0
      • L led mike

        I doubt you can return a .NET XmlDocument to Javascript but you might be able to return an MSXML interface. Of course then you don't have the simplicity of using XmlDocument in your C# code so I don't know if that is of any benefit.

        SpacixOne wrote:

        but not as text due to the overhead of phrasing it.

        you mean parsing it I guess. Are you sure the overhead is significant to warrant consideration? Also I have no idea what you are going to do with it in the javascript but I seems likely you want to copy some values from the XML into HTML elements for display etc. Can't you just do that using the DHTML interface from the C# code directly? Also when it comes to altering a HTML display in an embedded browser control you can generate the HTML using XML/XSLT transformation and then use one DHTML call to transfer the results into the browser document rather than using DHTML to access each discrete HTML element.

        led mike

        S Offline
        S Offline
        Spacix One
        wrote on last edited by
        #3

        led mike wrote:

        Also when it comes to altering a HTML display in an embedded browser control you can generate the HTML using XML/XSLT transformation and then use one DHTML call to transfer the results into the browser document rather than using DHTML to access each discrete HTML element.

        So you mean just write the whole page out to an XML file instead of just the data... I never thought about doing it that way... crap wish I we thought something along these lines a few weeks back (or posted it on here to get your comment back then) as that might have been easier in the long run. Currently to far along to change that much though :( Right now I'm just setting it up so there is an easy to configure display (IE HTML display) that allows to see the data that is saved via XML for web posting.

        led mike wrote:

        I doubt you can return a .NET XmlDocument to Javascript but you might be able to return an MSXML interface. Of course then you don't have the simplicity of using XmlDocument in your C# code so I don't know if that is of any benefit.

        Wonder how hard that would be to write a convert function, yet though converting it would still have the extra step and might not be much a benefit at all... Sounds like I may end up on worth than failure ;) heh


        -Spacix All your skynet questions[^] belong to solved

        L 1 Reply Last reply
        0
        • S Spacix One

          led mike wrote:

          Also when it comes to altering a HTML display in an embedded browser control you can generate the HTML using XML/XSLT transformation and then use one DHTML call to transfer the results into the browser document rather than using DHTML to access each discrete HTML element.

          So you mean just write the whole page out to an XML file instead of just the data... I never thought about doing it that way... crap wish I we thought something along these lines a few weeks back (or posted it on here to get your comment back then) as that might have been easier in the long run. Currently to far along to change that much though :( Right now I'm just setting it up so there is an easy to configure display (IE HTML display) that allows to see the data that is saved via XML for web posting.

          led mike wrote:

          I doubt you can return a .NET XmlDocument to Javascript but you might be able to return an MSXML interface. Of course then you don't have the simplicity of using XmlDocument in your C# code so I don't know if that is of any benefit.

          Wonder how hard that would be to write a convert function, yet though converting it would still have the extra step and might not be much a benefit at all... Sounds like I may end up on worth than failure ;) heh


          -Spacix All your skynet questions[^] belong to solved

          L Offline
          L Offline
          led mike
          wrote on last edited by
          #4

          SpacixOne wrote:

          So you mean just write the whole page out to an XML file instead of just the data

          Yes or even sections. That's  what all this nonsense about Web Parts and others are about. You can divide your page into sections with say a DIV element as a parent to all the content. Then you can transform XML/XSLT into the new content for that DIV and update just that part of the page. It's nothing new, it's all been around since like IE 4 I believe.

          led mike

          1 Reply Last reply
          0
          • S Spacix One

            I have an application where I use the web browser control and allow JScript to interact with my application though the object for scripting class that is set to com visible. I've been looking around the and I can't seem to find the limits of what data types/object you can pass to and from JScript. I know the basics work like int, float, string, ect... But I'd like to pass XML directly, but not as text due to the overhead of phrasing it. So does anyone know the limits or where to find out more information about the C# to JScript COM interop though the web browser control? I know the following works:

            public string feedJScriptXML()
            {
            //I know this example method is pointless, but it is just an example. The actual program sends XML it builds from other values
            XmlDocument myXMLDoc = new XmlDocument();
            myXMLDoc.Load("C:\myXMLfile.xml");
            return myXMLDoc.OuterXml;
            }

            Then send it as text to JScript and use it in JScript by

            function readCsharpXML()
            {
            var xmlString = window.external.feedJScriptXML();
            var theXML = new ActiveXObject("Microsoft.XMLDOM");
            theXML.load(xmlString);
            }

            The above is 100x better than writing the XML to a file and then reading the file into JScript... I think it might be better if I could dump the XML document into the JScript directly to save the extra phrase time... This application needs to read the XML 100's of times a minute so every little bit helps... The only information I've found on this is very basic via the MSDN C# tutorials http://msdn2.microsoft.com/en-us/vcsharp/bb798044.aspx?wt.slv=RightRail[^] and the WebBrowser.ObjectForScripting information at MSDN: http://msdn2.microsoft.com/en-us/library/system.windows.forms.webbrowser.objectforscripting(VS.80).aspx[^]


            -Spacix All your skynet questions[

            N Offline
            N Offline
            Not Active
            wrote on last edited by
            #5

            A long time ago I used XML Data Islands to contain the data for a very dynamic browser based application. This is essentially what you are doing. Have you thought about AJAX or script callbacks to get chunks of rather than the whole thing?


            only two letters away from being an asset

            S 1 Reply Last reply
            0
            • N Not Active

              A long time ago I used XML Data Islands to contain the data for a very dynamic browser based application. This is essentially what you are doing. Have you thought about AJAX or script callbacks to get chunks of rather than the whole thing?


              only two letters away from being an asset

              S Offline
              S Offline
              Spacix One
              wrote on last edited by
              #6

              The way I'm doing this is sort-of like AJAX without using the JScript XML HTTP GET request, but a custom API function call built into my API. The JScript can call for new data when it needs it or the user can invoke it to update/refresh manually. As I posted in the example code I didn't add all of the XML phrasing stuff, but a simple load and dump the XML. For the example it could have been just as easy to use File.readalllines on String.Join them it together to send the string.

                      string\[\] XmlLines = File.ReadAllLines("C:\\randomXMLfile.xml");
                      string XmlString = String.Join("\\n", XmlLines);
              

              But then where isn't an XML document or node, which was the original point of my question. Anyway enough of my clarification rant, the data is already in chunks and my example doesn't show it.


              -Spacix All your skynet questions[^] belong to solved

              N 1 Reply Last reply
              0
              • S Spacix One

                The way I'm doing this is sort-of like AJAX without using the JScript XML HTTP GET request, but a custom API function call built into my API. The JScript can call for new data when it needs it or the user can invoke it to update/refresh manually. As I posted in the example code I didn't add all of the XML phrasing stuff, but a simple load and dump the XML. For the example it could have been just as easy to use File.readalllines on String.Join them it together to send the string.

                        string\[\] XmlLines = File.ReadAllLines("C:\\randomXMLfile.xml");
                        string XmlString = String.Join("\\n", XmlLines);
                

                But then where isn't an XML document or node, which was the original point of my question. Anyway enough of my clarification rant, the data is already in chunks and my example doesn't show it.


                -Spacix All your skynet questions[^] belong to solved

                N Offline
                N Offline
                Not Active
                wrote on last edited by
                #7

                To clarify, you are have coded you own version of an existing framework. Now then, what was the question?


                only two letters away from being an asset

                S 1 Reply Last reply
                0
                • N Not Active

                  To clarify, you are have coded you own version of an existing framework. Now then, what was the question?


                  only two letters away from being an asset

                  S Offline
                  S Offline
                  Spacix One
                  wrote on last edited by
                  #8

                  Mark Nischalke wrote:

                  To clarify, you are have coded you own version of an existing framework.

                  I didn't recode and existing framework to my own version. AJAX requires a web server to serve an XML file. You open an JScript XML HTTP GET request and call an URL running a server side script (ASP.NET, PHP, and so on) that returns XML via a text string. I'm using a WinForm C# application with a webbrowser control that is running a local JScript page to dynamically request and display data XML returned to it. The page is setup as a JScript page so it is possible to easily change the interface (skinning, overall functionality, and so forth) without recompiling the application. The C# program just collects and then XML formats the data. This data could be posted to a webpage or just saved as XML on the users PC. The webbrowser control + JScript page allows the user to view it as it is being collected, or to view data that isn't saved (maybe logging is off) as it comes in.

                  Mark Nischalke wrote:

                  Now then, what was the question?

                  My question was as stated in my orgianl post. Is there a way to pass an System.Xml object to JScript via com using a [ComVisible(true)] class set to the WebBrowser.ObjectForScripting property of a web browser control?


                  -Spacix All your skynet questions[^] belong to solved

                  N 1 Reply Last reply
                  0
                  • S Spacix One

                    Mark Nischalke wrote:

                    To clarify, you are have coded you own version of an existing framework.

                    I didn't recode and existing framework to my own version. AJAX requires a web server to serve an XML file. You open an JScript XML HTTP GET request and call an URL running a server side script (ASP.NET, PHP, and so on) that returns XML via a text string. I'm using a WinForm C# application with a webbrowser control that is running a local JScript page to dynamically request and display data XML returned to it. The page is setup as a JScript page so it is possible to easily change the interface (skinning, overall functionality, and so forth) without recompiling the application. The C# program just collects and then XML formats the data. This data could be posted to a webpage or just saved as XML on the users PC. The webbrowser control + JScript page allows the user to view it as it is being collected, or to view data that isn't saved (maybe logging is off) as it comes in.

                    Mark Nischalke wrote:

                    Now then, what was the question?

                    My question was as stated in my orgianl post. Is there a way to pass an System.Xml object to JScript via com using a [ComVisible(true)] class set to the WebBrowser.ObjectForScripting property of a web browser control?


                    -Spacix All your skynet questions[^] belong to solved

                    N Offline
                    N Offline
                    Not Active
                    wrote on last edited by
                    #9

                    It is possible to serve web pages, or handle http requests without a webserver. It seems to me as though you are making this more complicated than it needs to be. Use xslt to transform you xml into the appropriate html to be displayed in a webbrowser control. Insert the XML into a XML data island via the HTML DOM.


                    only two letters away from being an asset

                    S 1 Reply Last reply
                    0
                    • N Not Active

                      It is possible to serve web pages, or handle http requests without a webserver. It seems to me as though you are making this more complicated than it needs to be. Use xslt to transform you xml into the appropriate html to be displayed in a webbrowser control. Insert the XML into a XML data island via the HTML DOM.


                      only two letters away from being an asset

                      S Offline
                      S Offline
                      Spacix One
                      wrote on last edited by
                      #10

                      I know what you mean but using the data island makes it harder to port over to Mono.Mozilla.WebBrowser.dll for a gecko based browser control.


                      -Spacix All your skynet questions[^] belong to solved

                      N 1 Reply Last reply
                      0
                      • S Spacix One

                        I know what you mean but using the data island makes it harder to port over to Mono.Mozilla.WebBrowser.dll for a gecko based browser control.


                        -Spacix All your skynet questions[^] belong to solved

                        N Offline
                        N Offline
                        Not Active
                        wrote on last edited by
                        #11

                        It is easier to give advice and answers when relevant information is stated up front. If this is a Windows app, you are guaranteed to have IE on the machine, why bother with trying to support others browser controls. I'm sure your project has a timeline and budget, does it including trying to develop something to support all possible combinations of technology? Good luck


                        only two letters away from being an asset

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups