QQuickWebEngineScript 类

在 JavaScript 引擎中启用脚本注入。 更多...

头: #include <QQuickWebEngineScript>
Since: Qt 5.9
实例化: WebEngineScript
继承: QObject

公共类型

enum InjectionPoint { DocumentCreation, DocumentReady, Deferred }
enum ScriptWorldId { MainWorld, ApplicationWorld, UserWorld }

特性

公共函数

QQuickWebEngineScript (QObject * parent = Q_NULLPTR)
InjectionPoint injectionPoint () const
QString name () const
bool runOnSubframes () const
void setInjectionPoint (InjectionPoint injectionPoint )
void setName (const QString & name )
void setRunOnSubframes (bool on )
void setSourceCode (const QString & code )
void setSourceUrl (const QUrl & url )
void setWorldId (ScriptWorldId scriptWorldId )
QString sourceCode () const
QUrl sourceUrl () const
QString toString () const
ScriptWorldId worldId () const

信号

void injectionPointChanged (InjectionPoint injectionPoint )
void nameChanged (const QString & name )
void runOnSubframesChanged (bool on )
void sourceCodeChanged (const QString & code )
void sourceUrlChanged (const QUrl & url )
void worldIdChanged (ScriptWorldId scriptWorldId )

额外继承成员

详细描述

在 JavaScript 引擎中启用脚本注入。

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.

成员类型文档编制

enum QQuickWebEngineScript:: InjectionPoint

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 毫秒 (以先到的为准) 运行脚本。

enum QQuickWebEngineScript:: ScriptWorldId

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

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

特性文档编制

injectionPoint : InjectionPoint

This property holds the point in the loading process at which the script will be executed.

默认值为 Deferred .

访问函数:

InjectionPoint injectionPoint () const
void setInjectionPoint (InjectionPoint injectionPoint )

通知程序信号:

void injectionPointChanged (InjectionPoint injectionPoint )

name : QString

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 )

通知程序信号:

void nameChanged (const QString & name )

runOnSubframes : bool

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 )

通知程序信号:

void runOnSubframesChanged (bool on )

sourceCode : QString

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

访问函数:

QString sourceCode () const
void setSourceCode (const QString & code )

通知程序信号:

void sourceCodeChanged (const QString & code )

另请参阅 QQuickWebEngineScript::sourceUrl .

sourceUrl : QUrl

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 )

通知程序信号:

void sourceUrlChanged (const QUrl & url )

另请参阅 QQuickWebEngineScript::sourceCode .

worldId : ScriptWorldId

This property holds the world ID defining which isolated world the script is executed in.

访问函数:

ScriptWorldId worldId () const
void setWorldId (ScriptWorldId scriptWorldId )

通知程序信号:

void worldIdChanged (ScriptWorldId scriptWorldId )

成员函数文档编制

QQuickWebEngineScript:: QQuickWebEngineScript ( QObject * parent = Q_NULLPTR)

构造新的 QQuickWebEngineScript 采用父级 parent .

QString QQuickWebEngineScript:: toString () const

Returns the script object as string.