fin
fin

Reputation: 1303

Winforms Host Javascript Content

Is it possible to host and run advanced javascript, such as this, directly on a WinForms application? To be ultra-clear, when I say, directly, I mean that I cannot use a web sever to host the content and then reference by URL. I need to be able to fulfil all the required functionality directly on the form.

Upvotes: 0

Views: 1165

Answers (1)

Johnie Karr
Johnie Karr

Reputation: 2822

Can you use an embeded html file and load that into a browser control?

Sample HTML:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
    <head>
        <title>
        </title>

            <script type="text/javascript">
                alert("hello");
            </script>
    </head>
    <body>
        TESTING!
    </body>
</html>

I named this file alertTest.html. It's properties are:

Build Action: Content
Copy to Output Directory: Copy always
FileName: alertTest.html

Then C# form:

public Form1()
{
    InitializeComponent();
    StreamReader reader = new StreamReader("alertTest.html");
    string html = reader.ReadToEnd();
    this.webBrowser1.DocumentText = html;
}

this will produce an alert box and the word TESTING! on the windows form.

Upvotes: 5

Related Questions