0

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.

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

3 Comments

That would be feasible but I'm concerned that the Javascript may need to be hosted in a webserver. Is it simply enough to embed a file and load it in a browser control? If so, then GREAT :-)
Javascript is always run on the client, not the server, so I see no reason why this would not work. I'm 90% sure that it will work as embedded content.
Thanks guys. I'll may as well give it a shot!

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.