在 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 引擎中啓用腳本注入。
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.
| 常量 | 值 | 描述 |
|---|---|---|
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
.
訪問函數:
| InjectionPoint | injectionPoint () const |
| void | setInjectionPoint (InjectionPoint injectionPoint ) |
通知程序信號:
| void | injectionPointChanged (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 ) |
通知程序信號:
| 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 ) |
通知程序信號:
| void | runOnSubframesChanged (bool on ) |
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 .
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 .
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 采用父級 parent .
Returns the script object as string.