QWebEngineScript 類封裝 JavaScript 程序。 更多...
| 頭: |
#include <QWebEngineScript>
|
| CMake: |
find_package(Qt6 REQUIRED COMPONENTS WebEngineCore)
target_link_libraries(mytarget PRIVATE Qt6::WebEngineCore)
|
| qmake: |
QT += webenginecore
|
| 在 QML: | webEngineScript |
| enum | InjectionPoint { DocumentCreation, DocumentReady, Deferred } |
| enum | ScriptWorldId { MainWorld, ApplicationWorld, UserWorld } |
| QWebEngineScript () | |
| QWebEngineScript (const QWebEngineScript & other ) | |
| ~QWebEngineScript () | |
| QWebEngineScript::InjectionPoint | injectionPoint () const |
| QString | name () const |
| bool | runsOnSubFrames () const |
| void | setInjectionPoint (QWebEngineScript::InjectionPoint p ) |
| void | setName (const QString & scriptName ) |
| void | setRunsOnSubFrames (bool on ) |
| void | setSourceCode (const QString & scriptSource ) |
| void | setSourceUrl (const QUrl & url ) |
| void | setWorldId (quint32 id ) |
| QString | sourceCode () const |
| QUrl | sourceUrl () 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 |
QWebEngineScript 啓用編程方式注入所謂的 用戶腳本 在 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
|
The default isolated world used for application-level functionality implemented in JavaScript. |
QWebEngineScript::UserWorld
|
2
|
由用戶設置的腳本使用的第一隔離世界若應用程序不使用更多世界。根據經驗,若將該功能暴露給應用程序用戶,每個單獨腳本應該都可能有其自己的隔離世界。 |
構造 null 腳本。
構造用戶腳本使用內容來自 other .
[noexcept]
QWebEngineScript::
~QWebEngineScript
()
銷毀腳本。
返迴加載過程中腳本將要執行的位置。默認值為 QWebEngineScript::Deferred .
注意: Getter function for property injectionPoint.
另請參閱 setInjectionPoint ().
返迴腳本的名稱。可能很有用,當檢索特定腳本從 QWebEngineScriptCollection .
注意: Getter function for property name.
另請參閱 setName () 和 QWebEngineScriptCollection::find ().
返迴
true
若腳本在頁麵每框架中執行,或
false
若它隻運行於主框架。
注意: Getter function for property runsOnSubFrames.
另請參閱 setRunsOnSubFrames ().
把執行腳本的點設為 p .
注意: setter 函數對於特性 injectionPoint .
另請參閱 injectionPoint () 和 InjectionPoint .
把腳本名稱設為 scriptName .
注意: setter 函數對於特性 name .
另請參閱 name ().
在除主框架外的子框架中執行腳本若
on
返迴
true
.
注意: setter 函數對於特性 runsOnSubFrames .
另請參閱 runsOnSubFrames ().
把腳本源設為 scriptSource .
注意: setter 函數對於特性 sourceCode .
另請參閱 sourceCode ().
Sets the remote source location of the user script to url .
不像 setSourceCode (), this function allows referring to user scripts that are not already loaded in memory, for instance, when stored on disk.
Setting this value will change the sourceCode of the script.
注意: At present, only file-based sources are supported.
注意: setter 函數對於特性 sourceUrl .
另請參閱 sourceUrl () 和 setSourceCode ().
把隔離世界的世界 ID 設為 id 當運行此腳本時。
必須介於
0
and
256
.
注意: setter 函數對於特性 worldId .
另請參閱 worldId ().
返迴腳本的源。
注意: Getter function for property sourceCode.
另請參閱 setSourceCode ().
Returns the remote source location of the user script (if any).
注意: Getter function for property sourceUrl.
另請參閱 setSourceUrl ().
[noexcept]
void
QWebEngineScript::
swap
(
QWebEngineScript
&
other
)
交換腳本的內容與內容為 other .
返迴定義腳本在哪個世界中執行的世界 ID。
注意: Getter function for property worldId.
另請參閱 setWorldId ().
返迴
true
若腳本不等於
other
,否則返迴
false
.
賦值 other 到腳本。
返迴
true
若腳本等於
other
,否則返迴
false
.