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.

特性文档编制

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.

name : 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]

Returns the size of the frame within the viewport.

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.

This method issues an asynchronous request for printing the web page into a PDF and returns immediately. To be informed about the result of the request, connect to the signal 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.