QQuickWebEngineScript Class
Enables the injection of scripts in the JavaScript engine. 更多...
头文件: | #include <QQuickWebEngineScript> |
开始支持版本: | Qt 5.9 |
Instantiated By: | WebEngineScript |
基类: | QObject |
公有类型
enum | InjectionPoint { DocumentCreation, DocumentReady, Deferred } |
enum | ScriptWorldId { MainWorld, ApplicationWorld, UserWorld } |
属性
|
|
- 1 个属性继承自 QObject
公有函数
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 |
- 32 个公有函数继承自 QObject
信号
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) |
- 2 个信号继承自 QObject
其他继承的成员
- 1 个公有槽函数继承自 QObject
- 1 个公有变量继承自 QObject
- 10 个静态公有成员继承自 QObject
- 9 个受保护的函数继承自 QObject
- 2 个受保护的变量继承自 QObject
详细描述
Enables the injection of scripts in the JavaScript engine.
The QQuickWebEngineScript type enables the programmatic injection of so called user scripts in the JavaScript engine at different points, determined by injectionPoint, during the loading of web content.
Scripts can be executed either in the main 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.
Constant | Value | Description |
---|---|---|
QQuickWebEngineScript::DocumentCreation | 2 | The script will be executed as soon as the document is created. This is not suitable for any DOM operation. |
QQuickWebEngineScript::DocumentReady | 1 | The script will run as soon as the DOM is ready. This is equivalent to the DOMContentLoaded event firing in JavaScript. |
QQuickWebEngineScript::Deferred | 0 | The script will run when the page load finishes, or 500 ms after the document is ready, whichever comes first. |
enum QQuickWebEngineScript::ScriptWorldId
The world ID defining which isolated world the script is executed in.
Constant | Value | Description |
---|---|---|
QQuickWebEngineScript::MainWorld | 0 | The world used by the page's web contents. It can be useful in order to expose custom functionality to web contents in certain scenarios. |
QQuickWebEngineScript::ApplicationWorld | 1 | The default isolated world used for application level functionality implemented in JavaScript. |
QQuickWebEngineScript::UserWorld | 2 | The first isolated world to be used by scripts set by users if the application is not making use of more worlds. As a rule of thumb, if that functionality is exposed to the application users, each individual script should probably get its own isolated world. |
属性
injectionPoint : InjectionPoint
This property holds the point in the loading process at which the script will be executed.
The default value is Deferred
.
访问函数:
InjectionPoint | injectionPoint() const |
void | setInjectionPoint(InjectionPoint injectionPoint) |
Notifier signal:
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) |
Notifier signal:
void | nameChanged(const QString &name) |
runOnSubframes : bool
This property holds whether the script is executed on every frame or only on the main frame.
Set this property to true
if the script is executed on every frame in the page, or false
if it is only run for the main frame. The default value is false
.
访问函数:
bool | runOnSubframes() const |
void | setRunOnSubframes(bool on) |
Notifier signal:
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) |
Notifier signal:
void | sourceCodeChanged(const QString &code) |
参见 QQuickWebEngineScript::sourceUrl.
sourceUrl : QUrl
This property holds the remote source location of the user script (if any).
Unlike 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.
Note: At present, only file-based sources are supported.
访问函数:
QUrl | sourceUrl() const |
void | setSourceUrl(const QUrl &url) |
Notifier signal:
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) |
Notifier signal:
void | worldIdChanged(ScriptWorldId scriptWorldId) |
成员函数
QQuickWebEngineScript::QQuickWebEngineScript(QObject *parent = Q_NULLPTR)
Constructs a new QQuickWebEngineScript with the parent parent.
QString QQuickWebEngineScript::toString() const
Returns the script object as string.