0

I Use WebEngineView QML Type to show a web page that have some link that need to open in a new tab. Links are somethings like

<a href="http://google.com" target="_blank">Go to google in new tab</a>

I want to open the URL of newViewRequested signal in an external browser but the WebEngineNewViewRequest has no 'url' property that I can use with Qt.openUrlExternally(request.url).

WebEngineNewViewRequest has a private member QUrl m_requestedUrl that not accesible as property in qml. How can I handle the issue,get the URL and open it in an external browser. Thanks.

mostafa88
  • 532
  • 1
  • 8
  • 20

1 Answers1

1

In Qt5, you can use navigationRequested signal to achieve this:

onNavigationRequested: function(request) {
    if (request.navigationType === WebEngineNavigationRequest.LinkClickedNavigation) {
        Qt.openUrlExternally(request.url)
    }
    request.action = WebEngineNavigationRequest.IgnoreRequest
}

The line of assigning IgnoreRequest to the action property is to make sure the URL is not opened in the WebEngineView.

Jake W
  • 2,788
  • 34
  • 39