WebEngineScript QML 類型

啓用在 JavaScript 引擎中以編程方式注入腳本。 更多...

import 語句: import QtWebEngine 1.8
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 由用戶設置的腳本使用的第一隔離世界若應用程序不使用更多世界。根據經驗,若將該功能暴露給應用程序用戶,每個單獨腳本應該都可能有其自己的隔離世界。

版權所有  © 2014-2026 樂數軟件    

工業和信息化部: 粵ICP備14079481號-1