QQuickWebEngineScript Class▲
-
Header: QQuickWebEngineScript
-
Since: Qt 5.9
-
Inherited By:
-
Instantiated By: qml-qtwebengine-webenginescript.xml
-
Inherits: QObject
Detailed Description▲
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.
Member Type Documentation▲
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. Besides these predefined IDs custom IDs can be used, but must be integers between 0 and 256.
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. |
Property Documentation▲
injectionPoint : InjectionPoint▲
This property holds the point in the loading process at which the script will be executed.
The default value is Deferred.
Access functions:
-
injectionPoint() const
-
void setInjectionPoint( injectionPoint)
Notifier signal:
-
void injectionPointChanged( injectionPoint)
name : QString▲
This property holds the name of the script.
Can be useful to retrieve a particular script from QQuickWebEngineProfile::userScripts.
Access functions:
-
name() const
-
void setName(const &name)
Notifier signal:
-
void nameChanged(const &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.
Access functions:
-
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.
Access functions:
-
sourceCode() const
-
void setSourceCode(const &code)
Notifier signal:
-
void sourceCodeChanged(const &code)
See Also▲
See also 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.
At present, only file-based sources are supported.
Access functions:
-
sourceUrl() const
-
void setSourceUrl(const &url)
Notifier signal:
-
void sourceUrlChanged(const &url)
See Also▲
See also QQuickWebEngineScript::sourceCode
worldId : ScriptWorldId▲
This property holds the world ID defining which isolated world the script is executed in.
Access functions:
-
worldId() const
-
void setWorldId( scriptWorldId)
Notifier signal:
-
void worldIdChanged( scriptWorldId)
Member Function Documentation▲
[explicit] QQuickWebEngineScript::QQuickWebEngineScript(QObject *parent = Q_NULLPTR)▲
Constructs a new QQuickWebEngineScript with the parent parent.
QString QQuickWebEngineScript::toString() const▲
Returns the script object as string.