Newbie Question: Howto make Javascript work?

  • Howdy!

    Sorry to make the forum a sample lab ;-) I am trying to make a simple process work:

    1. Open a webpage in the main window
    2. The page opens an empty popup via
    3. The page uses js to do some changes to the popup content
    4. The popup uses js to navigate the main window to a new url
    5. 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 ='', 'windowidzero', sOptions);
    win.[removed]("text into popup");

    } catch (e) {

    alert(e.description + "/" + + "/" + e.number);



  • Is javascript enabled in your QWebView? What does this return for you?:

    m_webView->page()->settings()->testAttribute( QWebSettings::JavascriptEnabled );

  • [quote author="ZapB" date="1311426271"]Is javascript enabled in your QWebView? What does this return for you?:

    Jepp, its enabled and working. I get the alert and the 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 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])

  • Hi Guys,

    Using webkit in QT5. Is it possible to open a new window when every time javascript opens a new window with out prompting for credentials.

    Will be fine if new window loads within application without asking for credentials.


Log in to reply

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