xwebview

package module
v0.0.0-...-ebcc607 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 16, 2025 License: MIT Imports: 18 Imported by: 0

README

XWebView

release xcgui golang GoDoc License

程序示例   项目文档  

介绍

xcgui 使用的 webview2,可创建到炫彩窗口或元素

获取

go get -u github.com/twgh/xwebview@latest

安装 WebView2 运行时

下载

预览

CreateByLayoutEle

CreateByWindow

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrEvalTimeout 是执行 js 代码超时.
	ErrEvalTimeout = errors.New("执行超时")
)

Functions

This section is empty.

Types

type Hint

type Hint int

Hint 用于配置窗口大小和调整大小的行为。

const (
	// HintNone 指定宽度和高度为默认大小
	HintNone Hint = iota

	// HintFixed 指定窗口大小不能被用户改变
	HintFixed

	// HintMin 指定宽度和高度为最小界限
	HintMin

	// HintMax 指定宽度和高度为最大界限
	HintMax
)

type WebView

type WebView struct {
	// contains filtered or unexported fields
}

func New

func New(hParent int, opt XcWebViewOption) *WebView

New 创建 webview 窗口到炫彩窗口或元素, 失败返回nil.

hParent: 炫彩窗口或元素句柄.

opt: 选项.

func (*WebView) Bind

func (w *WebView) Bind(name string, f interface{}) error

Bind 绑定一个Go函数,使其以给定的名称 作为全局 JavaScript 函数出现。内部使用 webview_init()。必须在UI线程执行.

f 必须是一个函数:

  • 函数参数没什么限制
  • 函数返回值可以是一个值或一个error
  • 函数返回值可以是一个值和一个error

func (*WebView) BindLog

func (w *WebView) BindLog(funcName ...string) error

BindLog 绑定一个日志输出函数, 参数不限个数, 在js代码中调用, 会在go控制台中输出.

funcName: 自定义函数名, 为空默认为glog.

func (*WebView) Destroy

func (w *WebView) Destroy()

Destroy 销毁一个 webview 并关闭原生窗口。

func (*WebView) Eval

func (w *WebView) Eval(js string)

Eval 执行 JS 代码(异步). 必须在UI线程执行.

func (*WebView) EvalAsync

func (w *WebView) EvalAsync(js string, f func(result interface{}, err error), timeout ...time.Duration) error

EvalAsync 执行 js 代码, 可在回调函数中异步获取结果. 必须在UI线程执行.

js: js 代码.

f: 可在回调函数中获取js代码执行结果以及错误, 为 nil 时, 等同于执行了 Eval. 注意这个回调函数是在协程中执行的, 不是在UI线程.

timeout: 超时时间, 为空默认10秒.

func (*WebView) EvalSync

func (w *WebView) EvalSync(js string, timeout ...time.Duration) (interface{}, error)

EvalSync 执行 js 代码, 同步取回返回值. 必须在UI线程执行.

js: js 代码.

timeout: 超时时间, 为空默认10秒.

func (*WebView) GetBrowser

func (w *WebView) GetBrowser() *edge.Chromium

func (*WebView) GetHWND

func (w *WebView) GetHWND() uintptr

GetHWND 返回 webview 所在的原生窗口句柄.

func (*WebView) GoBack

func (w *WebView) GoBack() *WebView

GoBack 网页_后退.

func (*WebView) GoForward

func (w *WebView) GoForward() *WebView

GoForward 网页_前进.

func (*WebView) Init

func (w *WebView) Init(js string)

Init 在新页面初始化时注入 JavaScript 代码。每次 webview 将打开一个新页面 - 此初始化代码将被执行。保证代码在 window.onload 之前执行。

func (*WebView) Navigate

func (w *WebView) Navigate(url string)

Navigate 导航 webview 到给定的 URL。URL 可能是数据 URI,即 "data:text/text,<html>...</html>"。通常不进行适当的 url 编码也是可以的, webview 会为你重新编码。

func (*WebView) Refresh

func (w *WebView) Refresh(forceReload ...bool) *WebView

Refresh 网页_刷新.

forceReload: 是否强制刷新, 默认为false. 为 true 时,浏览器会强制重新加载页面,忽略缓存。这意味着无论页面是否已经在本地缓存中,都会从服务器重新获取资源。

func (*WebView) Reload

func (w *WebView) Reload() *WebView

Reload 网页_重新加载.

func (*WebView) SetHtml

func (w *WebView) SetHtml(html string)

SetHtml 直接设置 webview 的 HTML。 页面的来源是 `about:blank`。

func (*WebView) SetSize

func (w *WebView) SetSize(width int, height int, hints Hint)

SetSize 更新原生窗口大小。参见 Hint 常量。

func (*WebView) SetTitle

func (w *WebView) SetTitle(title string)

SetTitle 更新原生窗口的标题。必须从 UI 线程调用。

func (*WebView) Stop

func (w *WebView) Stop() *WebView

Stop 网页_停止加载.

type XcWebViewOption

type XcWebViewOption struct {
	// WebView2 宿主窗口标题
	Title string
	// WebView2 宿主窗口类名
	ClassName string

	// DataPath 指定 WebView2 运行时用于浏览器实例的数据路径。
	DataPath string

	IconId uint

	// 左边
	Left int32
	// 顶边
	Top int32
	// 宽度
	Width int32
	// 高度
	Height int32

	// 填充父, 如果为true, 则 webView 会填满父窗口或元素, 固定坐标和尺寸会失效.
	FillParent bool

	// Debug 是否可开启开发者工具.
	Debug bool

	// AutoFocus 将在窗口获得焦点时尝试保持 webView 的焦点。
	AutoFocus bool
}

XcWebViewOption 是给 xcgui 定制的 WebViewOption.

Directories

Path Synopsis
example
CalcMD5 command
计算文件MD5.
计算文件MD5.
CreateByLayoutEle command
在布局元素中创建 WebView
在布局元素中创建 WebView
CreateByWindow command
在窗口中创建 WebView
在窗口中创建 WebView
internal
w32
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL