Skip to content

Commit e2a104b

Browse files
authored
Add SetHtml (#60)
1 parent a498365 commit e2a104b

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

common.go

+4
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ type WebView interface {
5858
// properly, webview will re-encode it for you.
5959
Navigate(url string)
6060

61+
// SetHtml sets the webview HTML directly.
62+
// The origin of the page is `about:blank`.
63+
SetHtml(html string)
64+
6165
// Init injects JavaScript code at the initialization of the new page. Every
6266
// time the webview will open a the new page - this initialization code will
6367
// be executed. It is guaranteed that code is executed before window.onload.

pkg/edge/chromium.go

+7
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,13 @@ func (e *Chromium) Navigate(url string) {
120120
)
121121
}
122122

123+
func (e *Chromium) NavigateToString(htmlContent string) {
124+
_, _, _ = e.webview.vtbl.NavigateToString.Call(
125+
uintptr(unsafe.Pointer(e.webview)),
126+
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(htmlContent))),
127+
)
128+
}
129+
123130
func (e *Chromium) Init(script string) {
124131
_, _, _ = e.webview.vtbl.AddScriptToExecuteOnDocumentCreated.Call(
125132
uintptr(unsafe.Pointer(e.webview)),

webview.go

+5
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ type browser interface {
3939
Embed(hwnd uintptr) bool
4040
Resize()
4141
Navigate(url string)
42+
NavigateToString(htmlContent string)
4243
Init(script string)
4344
Eval(script string)
4445
NotifyParentWindowPositionChanged() error
@@ -389,6 +390,10 @@ func (w *webview) Navigate(url string) {
389390
w.browser.Navigate(url)
390391
}
391392

393+
func (w *webview) SetHtml(html string) {
394+
w.browser.NavigateToString(html)
395+
}
396+
392397
func (w *webview) SetTitle(title string) {
393398
_title, err := windows.UTF16FromString(title)
394399
if err != nil {

0 commit comments

Comments
 (0)