I need to open a new window on click when there is window.open in html view... it does open as per my code. But when there is window.open with properties then it opens new window once and then it doesn't happen again
I have tried different things
from PyQt5 import QtCore, QtWidgets, QtWebEngineWidgets
from PyQt5.QtCore import QUrl
from PyQt5 import QtGui
from PyQt5.QtPrintSupport import QPrinter
from PyQt5.QtCore import *
from PyQt5.QtWidgets import (QApplication, QMainWindow, QPushButton,
QToolTip, QMessageBox, QLabel,QMenu,QKeySequenceEdit)
class MyPage(QtWebEngineWidgets.QWebEnginePage):
def triggerAction(self, action, checked=False):
if action == QtWebEngineWidgets.QWebEnginePage.OpenLinkInNewWindow:
self.createWindow(
QtWebEngineWidgets.QWebEnginePage.WebBrowserWindow
)
return super(MyPage, self).triggerAction(action, checked)
class MyWindow(QtWebEngineWidgets.QWebEngineView):
currentLoadProgress = 0
currentFile = ''
pdf_count = 0
def __init__(self,windows, parent=None):
super(MyWindow, self).__init__()
self.myPage = MyPage(self)
self.setPage(self.myPage)
self._windows = windows
self._windows.append(self)
self.resize(640, 480)
self.load(QtCore.QUrl.fromUserInput("file:///C:/Users/User/Desktop/default.html"))
self.show()
def createWindow(self, windows):
if windows == QtWebEngineWidgets.QWebEnginePage.NavigationTypeLinkClicked:
webview = MyWindow(self._windows)
webview.show()
return webview
if windows == QtWebEngineWidgets.QWebEnginePage.WebDialog:
webview = MyWindow([])
webview.show()
return webview
return super(MyWindow, self).createWindow(windows)
if __name__ == "__main__":
import sys
app = QApplication(sys.argv)
windows = []
a= MyWindow(windows)
a.show()
sys.exit(app.exec_())
<html>
<head>
<title>URL Error</title>
</head>
<body>
<center style="padding-top:100px">
<h2>Invaid URL</h2>
<p>No URL passed in argument!</p>
</center>
<a href="#" onclick="return openPopup('1');">JS function window.open with Properties</a><br><br>
<script language="javascript">
function openPopup(obj)
{
try
{
if(obj=="1")
{
window.open('https://www.google.com','DevSearch','top=0,left=0,width=950,height=550,status=yes,resizable=yes,scrollbars=yes');
}
}
catch(e)
{
alert("Script Error... Please Contact With Administrator ! ");
return false;
}
}
</script>
</body>
</html>
When the link is clicked with window.open with properties it show open the link in new tab, everytime the link is clicked.