from PyQt5.QtCore import QUrl from PyQt5.QtWidgets import QMainWindow, QApplication from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEnginePage from PyQt5.QtGui import QDesktopServices import os import sys class CustomWebEnginePage(QWebEnginePage): """ Custom WebEnginePage to customize how we handle link navigation """ # Store external windows. external_windows = [] def acceptNavigationRequest(self, url, _type, isMainFrame): if (_type == QWebEnginePage.NavigationTypeLinkClicked and url.host() != 'next.jefro.de'): # Send the URL to the system default URL handler. QDesktopServices.openUrl(url) return False return super().acceptNavigationRequest(url, _type, isMainFrame) class MainWindow(QMainWindow): def __init__(self, *args, **kwargs): super(MainWindow, self).__init__(*args, **kwargs) self.browser = QWebEngineView() self.browser.setPage(CustomWebEnginePage(self)) self.browser.setUrl(QUrl("https://next.jefro.de/")) self.setCentralWidget(self.browser) app = QApplication(sys.argv) window = MainWindow() window.show() app.exec_()