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.userScripts 和WebEngineProfile.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)
另请参阅 WebEngineScript 和WebEngineScriptCollection 。
属性文档
collection : list<WebEngineScript> |
该属性包含一个用户脚本对象的 JavaScript 数组。数组的值可以是WebEngineScript 基本类型或 JavaScript 字典。
该属性在 QtWebEngine 6.2 中引入。
方法文档
|
删除此集合中的所有脚本对象。
此方法在 QtWebEngine 6.2 中引入。
|
|
|
|
|
© 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.