diff options
Diffstat (limited to 'src/webenginequick/doc/snippets/qtwebengine_webengineview_newviewrequested.qml')
-rw-r--r-- | src/webenginequick/doc/snippets/qtwebengine_webengineview_newviewrequested.qml | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/webenginequick/doc/snippets/qtwebengine_webengineview_newviewrequested.qml b/src/webenginequick/doc/snippets/qtwebengine_webengineview_newviewrequested.qml new file mode 100644 index 000000000..6b10df752 --- /dev/null +++ b/src/webenginequick/doc/snippets/qtwebengine_webengineview_newviewrequested.qml @@ -0,0 +1,37 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +import QtQuick +import QtQuick.Window +import QtWebEngine + +//! [0] +QtObject { + id: windowParent + // Create the initial browsing windows and open the startup page. + Component.onCompleted: { + var firstWindow = windowComponent.createObject(windowParent); + firstWindow.webView.loadHtml('<input type="button" value="Click!" onclick="window.open("http://qt.io")">'); + } + + property Component windowComponent: Window { + // Destroy on close to release the Window's QML resources. + // Because it was created with a parent, it won't be garbage-collected. + onClosing: destroy() + visible: true + + property WebEngineView webView: webView_ + WebEngineView { + id: webView_ + anchors.fill: parent + + // Handle the signal. Dynamically create the window and + // use its WebEngineView as the destination of our request. + onNewWindowRequested: function(request) { + var newWindow = windowComponent.createObject(windowParent); + newWindow.webView.acceptAsNewWindow(request); + } + } + } +} +//! [0] |