views:

355

answers:

2

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"&gt;&lt;/script&gt;
<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  A: 

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....

Wayne
This is interesting indeed, thanks. Still looking for a "quick fix", but in any case this is what I'll try for now.
La-Brat
A: 

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.

La-Brat