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
|
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
|
返迴
true
if this object represents the page's main frame;
false
否則。
|
isValid
:
bool
|
返迴
true
if this object represents an existing frame;
false
否則。
Once a frame is invalid, it never becomes valid again.
|
name
:
string
|
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
|
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
|
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 ) |
運行包含的 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.