QWebEngineView, allow embedded JavaScript to use window.open



  • I am making a QWebEngine based "wrapper" for a pre-existing HTML/JavaScript application.
    (so that I can use the QWebChannel to interface this old HTML/JavaScript application with C++ functionality)

    Basically everything is working well. Except, some bits of functionality on the HTML/JavaScript side use window.open to spawn a URL in a new browser window.

    This doesn't work within the QWebEngine wrapper.

    I found the QWebEngineSettings::JavascriptCanOpenWindows setting and set it to true, but it still doesn't work.

    I'm not surprised really, as what browser would it open? Is there a signal emitted or that I can connect to, when the embedded javascript calls window.open, so that within my Qt side I could launch a new QWebView instance?

    How can this be accomplished?

    Thanks!


  • Moderators

    You can do that on two levels. Either subclass QWebEngineView and implement createWindow or a lower level way - subclass QWebEnginePage and implement createWindow.



  • EDIT: I subclassed QWebEngine and can see that createWindow does get called -but what next? It only comes with a "type" paramater.. The javascript is calling window.open(url) - so how do I get the URL? Or do I misunderstand something?



  • Ok this put me in the right direction, having subclassed both the view and page, and using createWindow and acceptNavigationRequest, I see how this all works now.. Thanks!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.