I have a very simple JavaScript file named as MyJava.htm as shown below:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
function ShowMe(message)
{
var n = message.length;
var s = a.toString();
alert("total length = " + s);
}
</script>
</head>
<body style='background-color:transparent'>
<P>Empty</P>
</body>
</html>
As you can see, there is an error in the code ('a' is undefined). I saved the file into my local machine's web server folder, which is c:\inetpub\wwwroot.
When I first run it using WPF WebBrowser control (this) as follows:
JavascriptInterface jint = new JavascriptInterface(mainWindow);
this.myBrowser.ObjectForScripting = jint;
this.myBrowser.Source = new Uri( @"http://127.0.0.1/myJava.htm");
this.myBrowser.InvokeScript("ShowMe", "Hello");
where mainWindow is a dialog. I'll get the error message saying 'a' is undefined.
Then, I went into the file MyJava.htm and corrected it (replacing variable 'a' with 'n'); saved the file; reran the WPF application.
I still get the 'a' is undefined error.
If I rename the file and change the URL accordingly, then everything works.
Apparently, the old script was being loaded even I've altered the content of the file.
How do I resolve this? How can I tell WPF (or whoever) to load the new contents from the URL?