webEngineFrame QML Value Type

webEngineFrame provides information about and control over a page frame. 更多...

import 語句: import QtWebEngine
Since: Qt 6.8
在 C++: QWebEngineFrame

特性

方法

詳細描述

A web engine frame represents a single frame within a web page, such as those created by <frame> or <iframe> HTML elements. An active WebEngineView has one or more frames arranged in a tree structure. The top-level frame, the root of this tree, can be accessed through the view's mainFrame 特性。

A frame's lifetime is, at most, as long as the WebEngineView object that produced it. However, frames may be created and deleted spontaneously and dynamically, for example through navigation and script execution.

特性文檔編製

children : list < webEngineFrame > [read-only, since QtWebEngine 6.10]

Returns a list of the frame's children in an arbitrary order.

If the frame could not be found, returns an empty list.

This property was introduced in QtWebEngine 6.10.

htmlName : string [read-only]

Returns the value of the frame's name HTML attribute, or an empty string if it has none.

If the frame could not be found, returns an empty string.

另請參閱 name .

isMainFrame : bool [read-only]

返迴 true if this object represents the page's main frame; false 否則。

isValid : bool [read-only]

返迴 true if this object represents an existing frame; false 否則。

Once a frame is invalid, it never becomes valid again.

名稱 : string [read-only]

Returns the frame name; that is, what would be returned by window.name in JavaScript.

If the frame could not be found, returns an empty string.

另請參閱 htmlName .

size : size [read-only]

The size of the frame within the viewport, measured in logical pixels. On devices with a scale factor other than 100%, this will not correspond to the on-screen size; instead, it will be the size before scaling is applied. In such cases, the size may contain fractional values.

If the frame could not be found, returns a default size with dimensions (-1, -1).

url : url [read-only]

Returns the URL of the content currently loaded in this frame.

If the frame could not be found, returns an empty URL.

方法文檔編製

void runJavaScript ( string script , uint worldId , variant callback )

void runJavaScript ( string script , variant callback )

運行包含的 JavaScript 代碼在 script on this frame, without checking whether the DOM of the page has been constructed.

為避免與頁麵中執行的其它腳本衝突,運行腳本的世界的指定通過 worldId 。世界 ID 值是相同的提供通過 QWebEngineScript::ScriptWorldId ,和介於 0 and 256 。若忽略 world ID,腳本運行在 MainWorld .

The callback parameter is optional. If a callback function is provided, it will be invoked after the script finishes running.

frame.runJavaScript("document.title", function(result) { console.log(result); });
					

僅純數據可以被返迴從 JavaScript 作為結果值。支持的數據類型包括所有 JSON 數據類型,例如, Date and ArrayBuffer 。不支持的數據類型包括,例如, Function and Promise .

The script will run in the same world as other scripts that are part of the loaded site.

警告: Do not execute lengthy routines in the callback function, because it might block the rendering of the web content.

For more information about injecting scripts, see 腳本注入 . For an alternative way to inject scripts, see WebEngineView::userScripts .

void printToPdf ( string filePath )

Prints the frame's current content to a PDF document and stores it under filePath . The resulting document will have A4 page size and portrait orientation.

為將網頁打印成 PDF,此方法發齣異步請求,並立即返迴。要通報請求的有關結果,連接到信號 WebEngineView::pdfPrintingFinished ().

另請參閱 WebEngineView::pdfPrintingFinished ().

void printToPdf ( variant callback )

Prints the frame's current content to a PDF document and returns it in a byte array. The resulting document will have A4 page size and portrait orientation.

The callback must take a string parameter. This string will contain the document's data upon successful printing and an empty string otherwise.