@@ -14,16 +14,18 @@ ScenarioDOMContentLoaded::ScenarioDOMContentLoaded(AppWindow* appWindow)
1414{
1515 //! [DOMContentLoaded]
1616 // Register a handler for the DOMContentLoaded event.
17- // Check whether the DOM content loaded
17+ // Event is raised when the DOM content is loaded
1818 CHECK_FAILURE(m_webView->add_DOMContentLoaded(
1919 Callback<ICoreWebView2DOMContentLoadedEventHandler>(
2020 [this](ICoreWebView2* sender, ICoreWebView2DOMContentLoadedEventArgs* args)
2121 -> HRESULT {
2222 m_webView->ExecuteScript(
23- L"let "
24- L"content=document.createElement(\"h2\");content.style.color='blue';"
25- L"content.textContent=\"This text was added by the host "
26- L"app\";document.body.appendChild(content);",
23+ LR"~(
24+ let content=document.createElement("h2");
25+ content.style.color='blue';
26+ content.textContent="This text was added by the host app";
27+ document.body.appendChild(content);
28+ )~",
2729 Callback<ICoreWebView2ExecuteScriptCompletedHandler>(
2830 [](HRESULT error, PCWSTR result) -> HRESULT { return S_OK; })
2931 .Get());
@@ -38,9 +40,9 @@ ScenarioDOMContentLoaded::ScenarioDOMContentLoaded(AppWindow* appWindow)
3840```
3941webView.CoreWebView2.DOMContentLoaded += (object sender, CoreWebView2DOMContentLoadedEventArgs arg) =>
4042{
41- webView.ExecuteScriptAsync("let "
42- "content=document.createElement(\"h2\");content.style.color="
43- "'blue';content.textContent= \"This text was added by the "
43+ webView.ExecuteScriptAsync("let " +
44+ "content=document.createElement(\"h2\");content.style.color=" +
45+ "'blue';content.textContent= \"This text was added by the " +
4446 "host app\";document.body.appendChild(content);");
4547};
4648webView.NavigateToString(@"<!DOCTYPE html><h1>DOMContentLoaded sample page</h1><h2>The content below will be added after DOM content is loaded </h2>");
@@ -62,7 +64,7 @@ interface ICoreWebView2DOMContentLoadedEventHandler;
6264[uuid(9810c82b-8483-4f1c-b2f4-6244f1010c05), object, pointer_default(unique)]
6365interface ICoreWebView2_2 : ICoreWebView2 {
6466 /// Add an event handler for the DOMContentLoaded event.
65- /// DOMContentLoaded fires when the initial html document has been parsed.
67+ /// DOMContentLoaded is raised when the initial html document has been parsed.
6668 /// This aligns with the the document's DOMContentLoaded event in html
6769 ///
6870 /// \snippet ScenarioDOMContentLoaded-Staging.cpp
0 commit comments