A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/AngleSharp/AngleSharp.Js/issues/19 below:

Insert & Execute Javascript code in HTML page? · Issue #19 · AngleSharp/AngleSharp.Js · GitHub

Hi,

Is it possible to pass Javascript code back and execute JavaScript function/method from C#?

For example :

ScriptingService javascriptService = new ScriptingService();
IConfiguration config = Configuration.Default.WithDefaultLoader(setup => setup.IsResourceLoadingEnabled = true).With(javascriptService).WithCss();

string scriptJS  = @"<script> 
                         function getTitle() { return document.title; }
                    </script>";

IDocument ashDocument = await BrowsingContext.New(config).OpenAsync("http://html5test.com");

// How to insert scriptJS  & excute getTitle() function?

// Perhaps to execute getTitle() function ....
JsValue jsGetTitle = javascriptService.Engine.GetJint(ashDocument).GetValue("getTitle");
string documentTitle = jsGetTitle.Invoke().AsString();
Console.WriteLine("Document Title: {0}", documentTitle);

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4