Newbie Question: Howto make Javascript work?
-
Howdy!
Sorry to make the forum a sample lab ;-) I am trying to make a simple process work:
- Open a webpage in the main window
- The page opens an empty popup via js:window.open
- The page uses js to do some changes to the popup content
- The popup uses js to navigate the main window to a new url
- The main window gets closed, but the popup remains
I have steps 1 and 2, the latter by implementing QWebView::createWindow. The script below used for testing, you wont get an error and no text appears in the popup. It works fine with Firefox, but also fails with Arora. Been looking the net up and down, but I cant find a simple code sample that explains how to make sure that javascript references work with the corresponding Qt objects.
Any hints are very welcome :)
@
alert("Start by hitting ok");
var win;
var sOptions = "resizable=no,scrollbars=yes,width=260,height=225";
try {
win = window.open('', 'windowidzero', sOptions); win.[removed]("text into popup");
} catch (e) {
alert(e.description + "/" + e.name + "/" + e.number);
}
@
-
[quote author="ZapB" date="1311426271"]Is javascript enabled in your QWebView? What does this return for you?:
[/quote]Jepp, its enabled and working. I get the alert and the window.open creates a new window. The win variable contains a reference, but win document write does nothing.
-
I made some progress and would like to share the results.
Making window.open work
I think there is no way around subclassing QWebView and QWebClass when you want to use them. The most simple way to get a new window is by implementing a new QWebView::createWindow(...) like@
QWebView* CWebView::createWindow(QWebPage::WebWindowType type)
{
return new QWebView(NULL);
}
@You should do something with the type parameter, which would be of QWebPage::WebBrowserWindow or QWebPage::WebModalDialog - which makes clear why you might need it :)
Writing into the new window
This generally works, but only after the primary page has been fully loaded. You should put your commands into a function and call that from the window onload function. I am not sure if this is a bug in its sense, but did not see this restriction in Firefox or Opera.Resizing and closing the window
If you set a size for the popup in javascript, this will not use it unless you implement a slot for the geometryChangeRequested signal. Same for closing the popup from js: implement a slot for the windowCloseRequested signal.Next on my list is manipulating the DOM using [removed])