mostafa88
mostafa88

Reputation: 542

Opening an URL in external browser when newViewRequested signal emited

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.

Upvotes: 0

Views: 1903

Answers (1)

Jake W
Jake W

Reputation: 2858

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.

Upvotes: 2

Related Questions