Документация
ОС Аврора 5.1.6
Обработка всплывающих окон
/*
* SPDX-FileCopyrightText: Copyright 2025 Open Mobile Platform LLC <community@omp.ru>
* SPDX-License-Identifier: Proprietary
*/
/**
* @file
* @brief Содержит пример использования расширения PopupExtension
*/
import QtQuick 2.0
import Sailfish.Silica 1.0
import ru.auroraos.WebView 1.0
Page {
id: page
property var webViewPopup: null
SilicaFlickable {
anchors.fill: parent
contentHeight: column.height
Column {
id: column
anchors.fill: parent
spacing: Theme.paddingLarge
PageHeader {
title: "Popup WebView"
}
Component {
id: webViewPopupComp
WebView {
anchors.fill: parent
MouseInput {}
TouchInput {}
KeyboardInput {}
}
}
Button {
anchors.horizontalCenter: parent.horizontalCenter
text: "Закрыть всплывающее окно"
onClicked: {
webViewPopup.destroy();
}
}
WebItem {
id: webView
url: "your.url"
width: parent.width
height: (page.height - webView.y) / 2
PopupExtension {
id: popupExtension
function beforePopup(url, frameName, userGesture) {
console.log(url.scheme, url.url)
console.log("frameName: " + frameName)
console.log("userGesture: " + userGesture)
if (frameName === 'NewPopupWindow btn_filtered') {
console.log("Отфильтровано");
return null;
}
console.log("Создать всплывающее окно webview");
if (webViewPopup != null) {
webViewPopup.destroy()
}
return webViewPopupComp;
}
function popupReady(newPopup) {
console.log("Всплывающее окно webview")
webViewPopup = newPopup
webViewPopup.parent = popupContainer
}
enabled: true
}
}
Connections {
target: webViewPopup
onClosing: {
webViewPopup.destroy();
}
}
Rectangle {
id: popupContainer
color: "black"
width: parent.width
height: (page.height - webView.y) / 2
}
}
}
}