在 JavaScript 引擎中启用脚本注入。 更多...
头: | #include <QQuickWebEngineScript> |
Since: | Qt 5.9 |
实例化: | WebEngineScript |
继承: | QObject |
该类在 Qt 5.9 引入。
enum | InjectionPoint { DocumentCreation, DocumentReady, Deferred } |
enum | ScriptWorldId { MainWorld, ApplicationWorld, UserWorld } |
|
|
QQuickWebEngineScript (QObject * parent = Q_NULLPTR) | |
QQuickWebEngineScript::InjectionPoint | injectionPoint () const |
QString | name () const |
bool | runOnSubframes () const |
void | setInjectionPoint (QQuickWebEngineScript::InjectionPoint injectionPoint ) |
void | setName (const QString & name ) |
void | setRunOnSubframes (bool on ) |
void | setSourceCode (const QString & code ) |
void | setSourceUrl (const QUrl & url ) |
void | setWorldId (QQuickWebEngineScript::ScriptWorldId scriptWorldId ) |
QString | sourceCode () const |
QUrl | sourceUrl () const |
QString | toString () const |
QQuickWebEngineScript::ScriptWorldId | worldId () const |
void | injectionPointChanged (QQuickWebEngineScript::InjectionPoint injectionPoint ) |
void | nameChanged (const QString & name ) |
void | runOnSubframesChanged (bool on ) |
void | sourceCodeChanged (const QString & code ) |
void | sourceUrlChanged (const QUrl & url ) |
void | worldIdChanged (QQuickWebEngineScript::ScriptWorldId scriptWorldId ) |
The QQuickWebEngineScript 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.
The point in the loading process at which the script will be executed.
常量 | 值 | 描述 |
---|---|---|
QQuickWebEngineScript::DocumentCreation
|
2
|
创建文档后尽快执行脚本。这不适于任何 DOM 操作。 |
QQuickWebEngineScript::DocumentReady
|
1
|
DOM 就绪后尽快运行脚本。这相当于
DOMContentLoaded
事件激发于 JavaScript 中。
|
QQuickWebEngineScript::Deferred
|
0
|
当页面加载完成时,或文档就绪后 500 毫秒 (以先到的为准) 运行脚本。 |
The world ID defining which isolated world the script is executed in. Besides these predefined IDs custom IDs can be used, but must be integers between
0
and
256
.
常量 | 值 | 描述 |
---|---|---|
QQuickWebEngineScript::MainWorld
|
0
|
由页面 Web 内容使用的世界。它可以是有用的在某些情景下把自定义功能暴露给 Web 内容。 |
QQuickWebEngineScript::ApplicationWorld
|
1
|
用于应用程序级 JavaScript 功能实现的默认隔离世界。 |
QQuickWebEngineScript::UserWorld
|
2
|
由用户设置的脚本使用的第一隔离世界若应用程序不使用更多世界。根据经验,若将该功能暴露给应用程序用户,每个单独脚本应该都可能有其自己的隔离世界。 |
This property holds the point in the loading process at which the script will be executed.
默认值为
Deferred
.
访问函数:
QQuickWebEngineScript::InjectionPoint | injectionPoint () const | |
void | setInjectionPoint (QQuickWebEngineScript::InjectionPoint injectionPoint ) | [见下文注意事项] |
注意: 此函数可以被援引,通过元对象系统和从 QML。见 Q_INVOKABLE .
通知程序信号:
void | injectionPointChanged (QQuickWebEngineScript::InjectionPoint injectionPoint ) |
This property holds the name of the script.
Can be useful to retrieve a particular script from QQuickWebEngineProfile::userScripts .
访问函数:
QString | name () const | |
void | setName (const QString & name ) | [见下文注意事项] |
注意: 此函数可以被援引,通过元对象系统和从 QML。见 Q_INVOKABLE .
通知程序信号:
void | nameChanged (const QString & name ) |
This property holds whether the script is executed on every frame or only on the main frame.
把此特性设为
true
若脚本在页面每框架中执行,或
false
if it is only run for the main frame. The default value is
false
.
访问函数:
bool | runOnSubframes () const | |
void | setRunOnSubframes (bool on ) | [见下文注意事项] |
注意: 此函数可以被援引,通过元对象系统和从 QML。见 Q_INVOKABLE .
通知程序信号:
void | runOnSubframesChanged (bool on ) |
This property holds the JavaScript source code of the user script.
访问函数:
QString | sourceCode () const | |
void | setSourceCode (const QString & code ) | [见下文注意事项] |
注意: 此函数可以被援引,通过元对象系统和从 QML。见 Q_INVOKABLE .
通知程序信号:
void | sourceCodeChanged (const QString & code ) |
另请参阅 QQuickWebEngineScript::sourceUrl .
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.
访问函数:
QUrl | sourceUrl () const | |
void | setSourceUrl (const QUrl & url ) | [见下文注意事项] |
注意: 此函数可以被援引,通过元对象系统和从 QML。见 Q_INVOKABLE .
通知程序信号:
void | sourceUrlChanged (const QUrl & url ) |
另请参阅 QQuickWebEngineScript::sourceCode .
This property holds the world ID defining which isolated world the script is executed in.
访问函数:
QQuickWebEngineScript::ScriptWorldId | worldId () const | |
void | setWorldId (QQuickWebEngineScript::ScriptWorldId scriptWorldId ) | [见下文注意事项] |
注意: 此函数可以被援引,通过元对象系统和从 QML。见 Q_INVOKABLE .
通知程序信号:
void | worldIdChanged (QQuickWebEngineScript::ScriptWorldId scriptWorldId ) |
Constructs a new QQuickWebEngineScript with the parent parent .
Returns the script object as string.
注意: 此函数可以被援引,通过元对象系统和从 QML。见 Q_INVOKABLE .