CefSharp LoadHtml [英] CefSharp LoadHtml
问题描述
有人可以向我解释CefSharp LoadHtml
函数如何工作吗?
LoadHtml(字符串html,字符串url)
html
和 url
参数代表?
我有兴趣从原始HTML加载页面字符串到CefSharp浏览器中。
更新:CefSharp有一个新的
LoadHtml(string html)
方法,将HTML加载为base64编码的数据URI。如下所述LoadHtml(string html,string url)
方法更可靠。
在 LoadHtml(字符串html,字符串url)
:
html
是您的HTML字符串,例如< html>< body> Hello world< / body>< / html>
。实际上,只要Chromium可以理解,您甚至可以在字符串中放入其他内容,例如SVG标记。
url
是必需的,因为您的HTML代码可能包含尝试执行AJAX调用的JavaScript,并且Web浏览器需要了解适用的安全限制。方案(例如 http:,关于:)和域(例如 localhost, google.com)会影响行为,例如单击链接,AJAX请求,iframe等。
如果只想呈现静态HTML,请使 url
变得独特,例如 http:// rendering /
(这样资源处理程序就不会与Web上的真实 url
重叠)。如果您需要加载HTML,然后与之交互或执行AJAX调用,请选择与您要与之交互的域匹配的 url
-例如,如果要设为其他Google主页并执行AJAX搜索查询,您将需要使用 https://www.google.com/
作为URL,以便与其进行通信。
您可以看到这里 LoadHtml
的源代码。
CefSharp的作用是:
- 为给定的
url注册资源处理程序
。 - 调用
Load(url)
告诉Chromium加载给定的url
。
然后,在后台:
< ol start = 3>
url
。 html
。 html
而不是URL的真实内容。
Could someone explain to me how the CefSharp LoadHtml
function works?
LoadHtml(string html, string url)
What do the html
and url
parameters represent?
I am interested in loading a page from a raw HTML string into the CefSharp browser.
Update: CefSharp has a new
LoadHtml(string html)
method that loads the HTML as a base64-encoded data URI. It is more reliable that theLoadHtml(string html, string url)
method described below.
In LoadHtml(string html, string url)
:
html
is your HTML string, e.g. "<html><body>Hello world</body></html>"
. Actually, you can even put other content in the string, such as SVG markup, as long as Chromium can understand it.
url
is needed because your HTML code may contain JavaScript that tries to perform AJAX calls, and the web browser needs to understand what security restrictions apply. The scheme (e.g. "http:", "about:") and domain (e.g. "localhost", "google.com") affect behaviour such as clicking on links, AJAX requests, iframes, etc.
If you want to simply render static HTML, make the url
something unique such as http://rendering/
(so that the resource handler does not overlap with a real url
on the web). If you need to load the HTML and then interact with it or perform AJAX calls, choose a url
that matches the domain you want to interact with - for example, if you want to make an alternative Google home page and perform AJAX search queries, you will want to use https://www.google.com/
as your URL so you can communicate with it.
You can see the source code for LoadHtml
here.
What CefSharp does is:
- Register a resource handler for the given
url
. - Call
Load(url)
to tell Chromium to load the givenurl
.
Then, under the hood:
- Chromium requests the
url
. - The resource handler intercepts the request, and returns your
html
. - Chromium renders your
html
instead of the real content of the URL.
这篇关于CefSharp LoadHtml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!