问题
I use Gecko Browser in C#. The following code shows that jQuery is loaded.
GeckoWebBrowser GWB = new GeckoWebBrowser .....
bool JSExec;
string JSresult = "";
string JStext = @"alert(jQuery.fn.jquery);";
using (AutoJSContext JScontext = new AutoJSContext(GWB.Window.JSContext))
{
JSExec = JScontext.EvaluateScript(JStext, (nsISupports)GWB.Window.DomWindow, out JSresult);
}
Alert box display 1.4.4
Is it possible to load a newer version of jQuery? Eg 2.0.2 => https://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js
Edit to replay @John
Yes I'm using GeckoFx. To to include a library, in
GeckoBrowser_DocumentCompleted()
I do this :
bool JSExec;
string JSresult = "";
GeckoScriptElement scriptJQuery = GWB.Document.CreateElement("script") as GeckoScriptElement;
scriptJQuery.Type = "text/javascript";
scriptJQuery.Src = "https://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js";
GWB.Document.Head.AppendChild(scriptJQuery);
string JStext = @"alert(jQuery.fn.jquery);";
using (AutoJSContext JScontext = new AutoJSContext(GWB.Window.JSContext))
{
JSExec = JScontext.EvaluateScript(JStext, (nsISupports)GWB.Window.DomWindow, out JSresult);
}
Hélas ! Alert display 1.4.4 !
回答1:
Assuming you're using https://bitbucket.org/geckofx, it doesn't have a version of jquery, or any other library. It's just a browser control.
So to include a library, you specify it on the html page you're loading, just like you would if you were using any other browser:
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
来源:https://stackoverflow.com/questions/24036383/how-to-load-another-jquery-version-from-geckowebbrowser-control