The QWebEngineScript class encapsulates a JavaScript program. 更多...
| 頭: | #include <QWebEngineScript> |
| qmake: | QT += webenginewidgets |
| Since: | Qt 5.5 |
| enum | InjectionPoint { DocumentCreation, DocumentReady, Deferred } |
| enum | ScriptWorldId { MainWorld, ApplicationWorld, UserWorld } |
| QWebEngineScript () | |
| QWebEngineScript (const QWebEngineScript & other ) | |
| ~QWebEngineScript () | |
| InjectionPoint | injectionPoint () const |
| bool | isNull () const |
| QString | name () const |
| bool | runsOnSubFrames () const |
| void | setInjectionPoint (InjectionPoint p ) |
| void | setName (const QString & scriptName ) |
| void | setRunsOnSubFrames (bool on ) |
| void | setSourceCode (const QString & scriptSource ) |
| void | setWorldId (quint32 id ) |
| QString | sourceCode () const |
| void | swap (QWebEngineScript & other ) |
| quint32 | worldId () const |
| bool | operator!= (const QWebEngineScript & other ) const |
| QWebEngineScript & | operator= (const QWebEngineScript & other ) |
| bool | operator== (const QWebEngineScript & other ) const |
The QWebEngineScript class encapsulates a JavaScript program.
QWebEngineScript enables the programmatic injection of so called 用戶腳本 在 JavaScript 引擎中的不同點,確定通過 injectionPoint (),在 Web 內容加載期間。
腳本可以執行於主 JavaScript world ,來自 web 內容的其它 JavaScript,或在它們自己的獨立世界。雖然頁麵的 DOM 可以被訪問從任何世界,但在某一世界中定義的 JavaScript 函數變量是不能從另一世界訪問的。 ScriptWorldId 為此目的提供瞭一些預定義 ID。
下列
Greasemonkey
屬性從 Qt 5.8 起支持:
@exclude
,
@include
,
@name
,
@match
,和
@run-at
.
使用 QWebEnginePage::scripts () 和 QWebEngineProfile::scripts () 能訪問與單個頁麵 (或共享同一 Profile 的多個頁麵) 關聯的腳本集閤。
此枚舉描述腳本注入的時間:
| 常量 | 值 | 描述 |
|---|---|---|
QWebEngineScript::DocumentCreation
|
2
|
創建文檔後盡快執行腳本。這不適於任何 DOM 操作。 |
QWebEngineScript::DocumentReady
|
1
|
DOM 就緒後盡快運行腳本。這相當於
DOMContentLoaded
事件激發於 JavaScript 中。
|
QWebEngineScript::Deferred
|
0
|
當頁麵加載完成時,或文檔就緒後 500 毫秒 (以先到的為準) 運行腳本。 |
此枚舉提供預定義世界 ID,用於把用戶腳本隔離到不同世界中:
| 常量 | 值 | 描述 |
|---|---|---|
QWebEngineScript::MainWorld
|
0
|
由頁麵 Web 內容使用的世界。它可以是有用的在某些情景下把自定義功能暴露給 Web 內容。 |
QWebEngineScript::ApplicationWorld
|
1
|
用於應用程序級 JavaScript 功能實現的默認隔離世界。 |
QWebEngineScript::UserWorld
|
2
|
由用戶設置的腳本使用的第一隔離世界若應用程序不使用更多世界。根據經驗,若將該功能暴露給應用程序用戶,每個單獨腳本應該都可能有其自己的隔離世界。 |
構造 null 腳本。
構造用戶腳本使用內容來自 other .
銷毀腳本。
返迴加載過程中腳本將要執行的位置。默認值為 QWebEngineScript::Deferred .
另請參閱 setInjectionPoint ().
返迴
true
若腳本為 null;否則返迴
false
.
返迴腳本的名稱。可能很有用,當檢索特定腳本從 QWebEngineScriptCollection .
另請參閱 setName (), QWebEngineScriptCollection::findScript (),和 QWebEngineScriptCollection::findScripts ().
返迴
true
若腳本在頁麵每框架中執行,或
false
若它隻運行於主框架。
另請參閱 setRunsOnSubFrames ().
把執行腳本的點設為 p .
另請參閱 injectionPoint () 和 InjectionPoint .
把腳本名稱設為 scriptName .
另請參閱 name ().
在除主框架外的子框架中執行腳本若
on
返迴
true
.
另請參閱 runsOnSubFrames ().
把腳本源設為 scriptSource .
另請參閱 sourceCode ().
把隔離世界的世界 ID 設為 id 當運行此腳本時。
另請參閱 worldId ().
返迴腳本的源。
另請參閱 setSourceCode ().
交換腳本的內容與內容為 other .
返迴定義腳本在哪個世界中執行的世界 ID。
另請參閱 setWorldId ().
返迴
true
若腳本不等於
other
,否則返迴
false
.
賦值 other 到腳本。
返迴
true
若腳本等於
other
,否則返迴
false
.