I am trying to run Javascript function inside ASP.Net
Web Application, and i am using WebBrowser
to do this:
JavaScriptSerializer js = new JavaScriptSerializer();
Dictionary<string, object> mainDic = (Dictionary<string, object>)js.DeserializeObject(fulljsFile);
String base64Content = (String)mainDic["html"];
String html = Base64.Base64Decode(base64Content);
Thread thread = new Thread(delegate()
{
WebBrowser browser = new WebBrowser();
browser.Navigate("about:blank");
if (browser.Document != null)
{
browser.Document.Write(string.Empty);
}
browser.Document.Write(html);
string name = (string)browser.Document.InvokeScript("extract");
});
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
thread.Join();
This is the html
var :
<html><script>
function extract()
{
return 'Steve';
};
</script>
</html>
The problem is that name
is empty instead of Steve
.
When i run it locally on my IIS
server it's working, but when i upload it to my server it's fail to return something to name
var.