Hi Support,
I am having hard time in injecting jquery after load url is complete . Let me show you my code.
I have tried two ways.
first i tried
Code: C#
public WebView webView { get; set; }
if (listSiteIds.Count > 0)
{
ParallelOptions parallelOptions = new ParallelOptions
{
MaxDegreeOfParallelism = 50
};
Parallel.ForEach(listSiteIds, parallelOptions, siteId =>
{
var eoThreadRunner = new ThreadRunner(siteId.ToString());
eoThreadRunner.Send(() =>
{
previewTasks.Add(Task.Factory.StartNew(() =>
{
previewGenerator = new PreviewGeneratorEOHeadless(eoThreadRunner.CreateWebView(), siteId);
previewGenerator.StartPreviewingAsync();
}));
});
});
_defaultDelay = minDelayInSeconds;
}
public async Task StartPreviewingAsync(){
// do some initialization and load url
InjectJquery();
}
private string GetJqueryVersion()
{
try
{
return webView.EvalScript("return $.fn.Jquery").ToString();
}
catch (Exception exception)
{
}
return "";
}
public void InjectJquery(){
string jQueryUrl = string.Format("window.setTimeout(function() {{ {0} }}, 5);", Properties.Resources.jquery_min); ;
webView.EvalScript($"var jq = document.createElement('script'); jq.src = '{jQueryUrl}'; document.getElementsByTagName('head')[0].appendChild(jq);");
}
GetJqueryVersion always return nothing it should return the version of jquery
second thing tried
Code: C#
string jqueryUrl = JsPath + "jqueryMinv1_11_2.js";
webView.EvalScript("var script = document.createElement('script');" +
"script.src = '" + jqueryUrl + "';" +
"document.getElementsByTagName('head')[0].appendChild(script);");
and when i invoke jquery function it gives exception $ is not defined whats wrong with the code