QWebView set body onload=window.open..., it return undefined



  • I want to rewrite QWebPage *createWindow(QWebPage::WebWindowType type) to get the open event, but when the page is like below it not work. document.write write "unfined". If I call the function on a button's click event, it works well. what's wrong with qtwebkit? Is there some settings needed to be set?
    @
    <body onload = myopen()>
    </script>
    function myopen(){
    win = window.open('http://www.baidu.com');
    document.write(win);
    }
    </script>
    <input value="click" type="button" ></input>
    </body>
    @
    @class webPage : public QWebPage
    {
    Q_OBJECT
    public:
    explicit webPage(QObject *parent = 0);

    protected:
    QWebPage *createWindow(QWebPage::WebWindowType type)
    {
    QWebView *wv = new QWebView;
    if (type == QWebPage::WebModalDialog)
    wv->setWindowModality(Qt::ApplicationModal);
    return wv->page();
    }
    };
    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    QWebView view;
    view.settings()->setAttribute(QWebSettings::JavascriptEnabled, true);
    view.settings()->setAttribute(QWebSettings::JavascriptCanOpenWindows, true);
    view.setPage(new WebPage);
    view.load(QUrl("file:///<path-to-html>"));
    view.show();
    return a.exec();
    }
    @


Log in to reply
 

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