이 페이지에서

QWebEngineScript Class

QWebEngineScript 클래스는 자바스크립트 프로그램을 캡슐화합니다. 더 보기...

헤더: #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)
void setName(const QString &)
void setRunsOnSubFrames(bool on)
void setSourceCode(const QString &)
void setSourceUrl(const QUrl &url)
void setWorldId(quint32)
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는 웹 콘텐츠 로딩 중 injectionPoint()에 의해 결정되는 여러 지점에서 JavaScript 엔진에 소위 사용자 스크립트를 프로그래밍 방식으로 삽입할 수 있게 해줍니다.

스크립트는 웹 콘텐츠에서 제공되는 나머지 JavaScript와 함께 기본 JavaScript 월드에서 실행되거나 자체적으로 분리된 월드에서 실행될 수 있습니다. 페이지의 DOM은 어느 월드에서나 액세스할 수 있지만 한 월드에 정의된 함수의 JavaScript 변수는 다른 월드에서 액세스할 수 없습니다. ScriptWorldId 에서는 이를 위해 미리 정의된 몇 가지 ID를 제공합니다.

지원되는 Greasemonkey 속성은 다음과 같습니다: @exclude, @include, @name, @match, 및 @run-at.

QWebEnginePage::scripts() 및 QWebEngineProfile::scripts()을 사용하여 단일 페이지 또는 동일한 프로필을 공유하는 여러 페이지와 연결된 스크립트 모음에 액세스합니다.

스크립트 주입도참조하세요 .

회원 유형 문서

enum QWebEngineScript::InjectionPoint

이 열거형은 스크립트 삽입 타이밍을 설명합니다:

상수설명
QWebEngineScript::DocumentCreation2문서가 생성되는 즉시 스크립트가 실행됩니다. 이 값은 DOM 작업에는 적합하지 않습니다.
QWebEngineScript::DocumentReady1스크립트는 DOM이 준비되는 즉시 실행됩니다. 이는 자바스크립트에서 DOMContentLoaded 이벤트가 실행되는 것과 동일합니다.
QWebEngineScript::Deferred0스크립트는 페이지 로드가 완료될 때 또는 문서가 준비된 후 500ms 중 먼저 도래하는 시점에 실행됩니다.

enum QWebEngineScript::ScriptWorldId

이 열거형은 사용자 스크립트를 다른 월드에 격리하기 위해 미리 정의된 월드 ID를 제공합니다:

상수설명
QWebEngineScript::MainWorld0페이지의 웹 콘텐츠가 사용하는 월드입니다. 특정 시나리오에서 웹 콘텐츠에 사용자 지정 기능을 노출하는 데 유용할 수 있습니다.
QWebEngineScript::ApplicationWorld1자바스크립트로 구현된 애플리케이션 수준 기능에 사용되는 기본 격리된 월드입니다.
QWebEngineScript::UserWorld2애플리케이션이 더 많은 월드를 사용하지 않는 경우 사용자가 설정한 스크립트에서 사용하는 첫 번째 격리된 월드입니다. 일반적으로 해당 기능이 애플리케이션 사용자에게 노출되는 경우 각 개별 스크립트는 자체 격리된 월드를 가져야 합니다.

속성 문서

injectionPoint : InjectionPoint

이 속성은 로딩 프로세스에서 스크립트가 실행될 지점을 저장합니다.

기본값은 QWebEngineScript::Deferred 입니다.

함수에 액세스합니다:

QWebEngineScript::InjectionPoint injectionPoint() const
void setInjectionPoint(QWebEngineScript::InjectionPoint)

InjectionPoint참조하세요 .

name : QString

이 속성은 스크립트의 이름을 저장합니다.

QWebEngineScriptCollection 에서 특정 스크립트를 검색하는 데 유용할 수 있습니다.

액세스 함수에 액세스합니다:

QString name() const
void setName(const QString &)

QWebEngineScriptCollection::find()도 참조하세요 .

runsOnSubFrames : bool

이 속성은 스크립트가 페이지의 모든 프레임에서 실행되는지, 아니면 메인 프레임에서만 실행되는지를 보유합니다.

액세스 함수:

bool runsOnSubFrames() const
void setRunsOnSubFrames(bool on)

sourceCode : QString

이 속성은 스크립트의 소스를 보유합니다.

액세스 함수:

QString sourceCode() const
void setSourceCode(const QString &)

sourceUrl : QUrl

이 속성은 사용자 스크립트의 원격 소스 위치(있는 경우)를 보유합니다.

setSourceCode()와 달리 이 속성을 설정하면 디스크에 저장된 경우와 같이 메모리에 아직 로드되지 않은 사용자 스크립트를 참조할 수 있습니다.

이 값을 설정하면 스크립트의 sourceCode 주소가 변경됩니다.

참고: 현재 파일 기반 소스만 지원됩니다.

액세스 함수:

QUrl sourceUrl() const
void setSourceUrl(const QUrl &url)

sourceCode참조하세요 .

worldId : quint32

이 프로퍼티에는 스크립트가 실행되는 월드를 정의하는 월드 ID가 있습니다.

0256 사이여야 합니다.

함수에 액세스합니다:

quint32 worldId() const
void setWorldId(quint32)

멤버 함수 문서

QWebEngineScript::QWebEngineScript()

널 스크립트를 작성합니다.

QWebEngineScript::QWebEngineScript(const QWebEngineScript &other)

other 의 내용을 사용하여 사용자 스크립트를 작성합니다.

[noexcept] QWebEngineScript::~QWebEngineScript()

스크립트를 삭제합니다.

[noexcept] void QWebEngineScript::swap(QWebEngineScript &other)

스크립트의 내용을 other 의 내용으로 바꿉니다.

bool QWebEngineScript::operator!=(const QWebEngineScript &other) const

스크립트가 other 과 같지 않으면 true 을 반환하고, 그렇지 않으면 false 을 반환합니다.

QWebEngineScript &QWebEngineScript::operator=(const QWebEngineScript &other)

other 을 스크립트에 할당합니다.

bool QWebEngineScript::operator==(const QWebEngineScript &other) const

스크립트가 other 과 같으면 true 을 반환하고, 그렇지 않으면 false 을 반환합니다.

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.