QWebEngineScript class encapsulates a JavaScript program. 更多...
Header: | #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 () | |
QWebEngineScript::InjectionPoint | injectionPoint () const |
bool | isNull () 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 | 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 |
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 () 去访问与单个页面或共享同一配置文件的多个页面关联的脚本集合。
另请参阅 脚本注入 .
此枚举描述脚本注入的时间:
常量 | 值 | 描述 |
---|---|---|
QWebEngineScript::DocumentCreation
|
2
|
文档被创建后尽快执行脚本。这不适合任何 DOM 操作。 |
QWebEngineScript::DocumentReady
|
1
|
DOM 就绪后尽快运行脚本。这相当于
DOMContentLoaded
事件激发于 JavaScript 中。
|
QWebEngineScript::Deferred
|
0
|
当页面加载完成时,或文档就绪后 500 毫秒 (以先到的为准) 运行脚本。 |
此枚举提供预定义世界 ID,用于把用户脚本隔离到不同世界中:
常量 | 值 | 描述 |
---|---|---|
QWebEngineScript::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. |
QWebEngineScript::ApplicationWorld
|
1
|
The default isolated world used for application level functionality implemented in JavaScript. |
QWebEngineScript::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. |
构造 null 脚本。
Constructs a user script using the contents of other .
销毁脚本。
Returns the point in the loading process at which the script will be executed. The default value is QWebEngineScript::Deferred .
另请参阅 setInjectionPoint ().
返回
true
若脚本为 null;否则返回
false
.
返回脚本的名称。可能是有用的,对检索特定脚本从 QWebEngineScriptCollection .
另请参阅 setName (), QWebEngineScriptCollection::findScript (),和 QWebEngineScriptCollection::findScripts ().
返回
true
若脚本在页面每框架中执行,或
false
若它只运行于主框架。
另请参阅 setRunsOnSubFrames ().
把执行脚本的点设为 p .
另请参阅 injectionPoint () 和 InjectionPoint .
把脚本名称设为 scriptName .
另请参阅 name ().
Executes the script on sub frames in addition to the main frame if
on
返回
true
.
另请参阅 runsOnSubFrames ().
把脚本源设为 scriptSource .
另请参阅 sourceCode ().
把隔离世界的世界 ID 设为 id 当运行此脚本时。
必须介于
0
and
256
.
另请参阅 worldId ().
返回脚本的源。
另请参阅 setSourceCode ().
Swaps the contents of the script with the contents of other .
返回定义脚本在哪个世界中执行的世界 ID。
另请参阅 setWorldId ().
返回
true
若脚本不等于
other
,否则返回
false
.
赋值 other 到脚本。
返回
true
若脚本等于
other
,否则返回
false
.