WebEngineScript QML 类型

启用在 JavaScript 引擎中以编程方式注入脚本。 更多...

import 语句: import QtWebEngine 1.10
Since: QtWebEngine 1.1
实例化: QQuickWebEngineScript

特性

详细描述

The WebEngineScript type enables the programmatic injection of so called 用户脚本 在 JavaScript 引擎中的不同点,确定通过 injectionPoint , during the loading of web content.

脚本可以执行于主 JavaScript world , along with the rest of the JavaScript coming from the web contents, or in their own isolated world. While the DOM of the page can be accessed from any world, JavaScript variables of a function defined in one world are not accessible from a different one. The worldId property provides some predefined IDs for this purpose.

下列 Greasemonkey 属性从 Qt 5.8 起支持: @exclude , @include , @name , @match ,和 @run-at .

使用 WebEngineView.userScripts to access a list of scripts attached to the web view.

特性文档编制

injectionPoint : enumeration

The point in the loading process at which the script will be executed. The default value is Deferred .

常量 描述
WebEngineScript.DocumentCreation 创建文档后尽快执行脚本。这不适于任何 DOM 操作。
WebEngineScript.DocumentReady DOM 就绪后尽快运行脚本。这相当于 DOMContentLoaded 事件激发于 JavaScript 中。
WebEngineScript.Deferred 当页面加载完成时,或文档就绪后 500 毫秒 (以先到的为准) 运行脚本。

name : string

The name of the script. Can be useful to retrieve a particular script from WebEngineView.userScripts .

runOnSubframes : int

把此特性设为 true 若脚本在页面每框架中执行,或 false if it is only ran for the main frame. The default value is false .

sourceCode : string

This property holds the JavaScript source code of the user script.

另请参阅 sourceUrl .

sourceUrl : url

This property holds the remote source location of the user script (if any).

不像 sourceCode , this property allows referring to user scripts that are not already loaded in memory, for instance, when stored on disk.

Setting this property will change the sourceCode of the script.

注意: At present, only file-based sources are supported.

另请参阅 sourceCode .

worldId : enumeration

The world ID defining which isolated world the script is executed in.

常量 描述
WebEngineScript.MainWorld 由页面 Web 内容使用的世界。它可以是有用的在某些情景下把自定义功能暴露给 Web 内容。
WebEngineScript.ApplicationWorld 用于应用程序级 JavaScript 功能实现的默认隔离世界。
WebEngineScript.UserWorld 由用户设置的脚本使用的第一隔离世界若应用程序不使用更多世界。根据经验,若将该功能暴露给应用程序用户,每个单独脚本应该都可能有其自己的隔离世界。