WebEngineScriptCollection QML Type

管理用户脚本集合。更多

Import Statement: import QtWebEngine
Since: QtWebEngine 6.2

属性

  • collection : list<WebEngineScript> (since QtWebEngine 6.2)

方法

  • void clear() (since QtWebEngine 6.2)
  • bool contains(WebEngineScript script) (since QtWebEngine 6.2)
  • list<WebEngineScript> find(string name) (since QtWebEngine 6.2)
  • void insert(WebEngineScript script) (since QtWebEngine 6.2)
  • void insert(list<WebEngineScript> list) (since QtWebEngine 6.2)
  • bool remove(WebEngineScript script) (since QtWebEngine 6.2)

详细说明

WebEngineScriptCollection 处理用户脚本集合,该集合在加载网页内容时注入 JavaScript 引擎。

使用WebEgineView.userScriptsWebEngineProfile.userScripts 可访问与单个页面或共享相同配置文件的多个页面相关联的脚本集合。

QML 中的用户脚本对象集合可通过简单赋值给WebEngineScriptCollection.collection 属性或 WebEngineScriptCollection 方法为一组用户脚本对象创建。

注: 使用集合属性时,新用户脚本可通过 JavaScript 字典实例化。

请参阅下面的代码片段演示用法:

  • 使用 JavaScript 字典的集合属性
    var scriptFoo = { name: "Foo",
                    sourceUrl: Qt.resolvedUrl("foo.js"),
                    injectionPoint: WebEngineScript.DocumentReady }
    
    webEngineView.userScripts.collection = [ scriptFoo, scriptBar ];
  • 使用用户脚本对象作为值类型的集合属性
    var script = WebEngine.script()
    script.name = "FOO"
    webEngineView.userScripts.collection = [ script ]
  • 用户脚本集合插入方法只能用于值类型或值类型列表
    var script = WebEngine.script()
    script.name = "FOO"
    webEngineView.userScripts.insert(script)
    
    var list = [ script ]
    webEngineView.userScripts.insert(list)

另请参阅 WebEngineScriptWebEngineScriptCollection

属性文档

collection : list<WebEngineScript> [since QtWebEngine 6.2]

该属性包含一个用户脚本对象的 JavaScript 数组。数组的值可以是WebEngineScript 基本类型或 JavaScript 字典。

该属性在 QtWebEngine 6.2 中引入。


方法文档

[since QtWebEngine 6.2] void clear()

删除此集合中的所有脚本对象。

此方法在 QtWebEngine 6.2 中引入。


[since QtWebEngine 6.2] bool contains(WebEngineScript script)

如果指定的script 在集合中,则返回true ,否则返回false

此方法在 QtWebEngine 6.2 中引入。

另请参阅 find().


[since QtWebEngine 6.2] list<WebEngineScript> find(string name)

返回具有给定name 的所有用户脚本对象的列表。

此方法在 QtWebEngine 6.2 中引入。

另请参阅 contains().


[since QtWebEngine 6.2] void insert(WebEngineScript script)

向集合中插入一个script

此方法在 QtWebEngine 6.2 中引入。

另请参阅 remove().


[since QtWebEngine 6.2] void insert(list<WebEngineScript> list)

listWebEngineScript 值插入用户脚本集合。

此方法在 QtWebEngine 6.2 中引入。

另请参阅 remove().


[since QtWebEngine 6.2] bool remove(WebEngineScript script)

如果给定的script 已从集合中删除,则返回true

此方法在 QtWebEngine 6.2 中引入。

另请参阅 insert().


© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.