简体   繁体   中英

How do I load a local HTML into CefSharp that contains a CSS-stylesheet?

OS: Windows 7
Cef Version: Wpf

Hello all,
I'm trying to load a local HTML file ( https://pastebin.com/wgnTKcpS ) that uses the MathQuill formula editor ( http://mathquill.com ). However, when using this code:

MathQuillBrowser.IsBrowserInitializedChanged += (s, e) =>
{
    if (MathQuillBrowser.IsBrowserInitialized)
        MathQuillBrowser.LoadHtml(File.ReadAllText(Environment.CurrentDirectory + "/mathquill.html"), "https://somefakeurl-mathquill.com");
};

to load the HTML file into the ChromiumBrowser , the MathQuill span doesn't show up in the ChromiumBrowser at the Wpf window. What am I doing wrong?

How to reproduce the problem:

  • Create a new Wpf Application in VS and install CefSharp with Nuget
  • Go to the bin\\x86\\Debug file of the project and put the HTML mentioned above (in a file named mathquill.html) and the latest version of MathQuill.
  • Create a ChromiumBrowser control and add it to the main control of some window.
  • Load the Html into ChromiumBrowser with the code mentioned above.

Important note: The C# code above works (html elements show up) with elements that don't load external CSS stylesheets. Also, the html code works as expected if you open it in a browser like Chrome.

Cef browser doesn't know where the CSS file is, so it can't find it. The easy solution is to use a CDN ( https://cdnjs.com/libraries/mathquill , for MathQuill).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM