1
votes

Here's my scenario:

I'm using the WebBrowser control in a WinForms app to display data. The HTML is served via the DocumentText property and I want to use jQuery to interact with the contents. Loading jQuery from the web (Google APIs) works:

actual html inside DocumentText, head block:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
// jquery specific functions...
</script>

I want to load the jQuery file from the filesystem, like this:

<script type="text/javascript" src="file:///E:/path/to/jquery.js"></script>

But it fails. I reckon it is blocked by IE's security zone settings (about:blank anyone?). I've tried using MotW but that doesn't work either. How do I do this properly?

3

3 Answers

3
votes

You could think about embedding a simple HTTP server into your application running on its own thread. Maybe not be perfect but may just do what you require.

See Embedded .NET HTTP Server or Simple HTTP Server Skeleton in C# as two examples.

Whether this architecture is right for you is another story, but it may just allow you to server static content locally without having to worry about the security restrictions of your control. You may have some firewall issues but I would say this should be minimal as your connections are all over loopback.

Hope this offers something to think about anyway....

2
votes

Quick fix #49: create temporary html files in Path.GetTempPath() and navigate to them. This way, there are less restrictions, so local resources like scripts are allowed to run. Cleanup on exit.

Bonus: Automatic caching.

0
votes

Use awesomium1 webbrowser control. It supports jquery on Winforms and WPF. It is free for non-commercial apps. I am planning on recommending it for some of my employers legacy apps which cause headaches with IE8 support.