QQuickWebEngineScript 類

在 JavaScript 引擎中啓用腳本注入。 更多...

頭: #include <QQuickWebEngineScript>
Since: Qt 5.9
實例化: WebEngineScript
繼承: QObject

該類在 Qt 5.9 引入。

公共類型

enum InjectionPoint { DocumentCreation, DocumentReady, Deferred }
enum ScriptWorldId { MainWorld, ApplicationWorld, UserWorld }

特性

公共函數

QQuickWebEngineScript (QObject * parent = Q_NULLPTR)
QQuickWebEngineScript::InjectionPoint injectionPoint () const
QString name () const
bool runOnSubframes () const
void setInjectionPoint (QQuickWebEngineScript::InjectionPoint injectionPoint )
void setName (const QString & name )
void setRunOnSubframes (bool on )
void setSourceCode (const QString & code )
void setSourceUrl (const QUrl & url )
void setWorldId (QQuickWebEngineScript::ScriptWorldId scriptWorldId )
QString sourceCode () const
QUrl sourceUrl () const
QString toString () const
QQuickWebEngineScript::ScriptWorldId worldId () const

信號

void injectionPointChanged (QQuickWebEngineScript::InjectionPoint injectionPoint )
void nameChanged (const QString & name )
void runOnSubframesChanged (bool on )
void sourceCodeChanged (const QString & code )
void sourceUrlChanged (const QUrl & url )
void worldIdChanged (QQuickWebEngineScript::ScriptWorldId scriptWorldId )

詳細描述

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.

成員類型文檔編製

enum QQuickWebEngineScript:: InjectionPoint

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 毫秒 (以先到的為準) 運行腳本。

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 .

常量 描述
QQuickWebEngineScript::MainWorld 0 由頁麵 Web 內容使用的世界。它可以是有用的在某些情景下把自定義功能暴露給 Web 內容。
QQuickWebEngineScript::ApplicationWorld 1 用於應用程序級 JavaScript 功能實現的默認隔離世界。
QQuickWebEngineScript::UserWorld 2 由用戶設置的腳本使用的第一隔離世界若應用程序不使用更多世界。根據經驗,若將該功能暴露給應用程序用戶,每個單獨腳本應該都可能有其自己的隔離世界。

特性文檔編製

injectionPoint : InjectionPoint

This property holds the point in the loading process at which the script will be executed.

默認值為 Deferred .

訪問函數:

QQuickWebEngineScript::InjectionPoint injectionPoint () const
void setInjectionPoint (QQuickWebEngineScript::InjectionPoint injectionPoint ) [見下文注意事項]

注意: 此函數可以被援引,通過元對象係統和從 QML。見 Q_INVOKABLE .

通知程序信號:

void injectionPointChanged (QQuickWebEngineScript::InjectionPoint injectionPoint )

name : QString

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 ) [見下文注意事項]

注意: 此函數可以被援引,通過元對象係統和從 QML。見 Q_INVOKABLE .

通知程序信號:

void nameChanged (const QString & name )

runOnSubframes : bool

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 ) [見下文注意事項]

注意: 此函數可以被援引,通過元對象係統和從 QML。見 Q_INVOKABLE .

通知程序信號:

void runOnSubframesChanged (bool on )

sourceCode : QString

This property holds the JavaScript source code of the user script.

訪問函數:

QString sourceCode () const
void setSourceCode (const QString & code ) [見下文注意事項]

注意: 此函數可以被援引,通過元對象係統和從 QML。見 Q_INVOKABLE .

通知程序信號:

void sourceCodeChanged (const QString & code )

另請參閱 QQuickWebEngineScript::sourceUrl .

sourceUrl : QUrl

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 ) [見下文注意事項]

注意: 此函數可以被援引,通過元對象係統和從 QML。見 Q_INVOKABLE .

通知程序信號:

void sourceUrlChanged (const QUrl & url )

另請參閱 QQuickWebEngineScript::sourceCode .

worldId : ScriptWorldId

This property holds the world ID defining which isolated world the script is executed in.

訪問函數:

QQuickWebEngineScript::ScriptWorldId worldId () const
void setWorldId (QQuickWebEngineScript::ScriptWorldId scriptWorldId ) [見下文注意事項]

注意: 此函數可以被援引,通過元對象係統和從 QML。見 Q_INVOKABLE .

通知程序信號:

void worldIdChanged (QQuickWebEngineScript::ScriptWorldId scriptWorldId )

成員函數文檔編製

QQuickWebEngineScript:: QQuickWebEngineScript ( QObject * parent = Q_NULLPTR)

Constructs a new QQuickWebEngineScript with the parent parent .

QString QQuickWebEngineScript:: toString () const

Returns the script object as string.

注意: 此函數可以被援引,通過元對象係統和從 QML。見 Q_INVOKABLE .