在QtWebkit
中,使用QWebSettings
类,我可以使用JavaScript命令window.close();
启用关闭窗口的权限:
setAttribute(QWebSettings::JavascriptCanCloseWindows, true);
但在QtWebEngine
中,此类属性不存在:http://doc.qt.io/qt-5/qwebenginesettings.html#WebAttribute-enum
如何允许JavaScript使用QWebEngineView
关闭任何window.close()
?
答案 0 :(得分:0)
实际上,这个属性在Qt WebEngine中不再存在。
但是,您可以使用QWebEnginePage中的信号windowCloseRequested关闭所有视图,并将其连接到关闭窗口的插槽。 Demo Browser example中的文件webview.cpp中有一个使用示例:
connect(page(), &WebPage::windowCloseRequested, this, &QWidget::close);