mirror of https://github.com/vitalif/phantomjs
Introduce "onLoadFinished" event, fired when loading is completed.
It is now possible to specify only the URL in the open() function. The loading callback can be set using onLoadFinished. Example use: var page = new WebPage(); page.onLoadFinished = function () { console.log("Done!"); phantom.exit(); }; page.open("http://example.com");1.2
parent
d9d9d5a8ac
commit
c8504f6994
|
@ -19,6 +19,16 @@ window.WebPage = function() {
|
|||
this.loadStarted.connect(this.handlers.loadStarted);
|
||||
});
|
||||
|
||||
page.__defineSetter__("onLoadFinished", function(f) {
|
||||
if (this.handlers && typeof this.handlers.loadFinished === 'function') {
|
||||
try {
|
||||
this.loadFinished.disconnect(this.handlers.loadFinished);
|
||||
} catch (e) {}
|
||||
}
|
||||
this.handlers.loadFinished = f;
|
||||
this.loadFinished.connect(this.handlers.loadFinished);
|
||||
});
|
||||
|
||||
page.onAlert = function (msg) {};
|
||||
|
||||
page.onConsoleMessage = function (msg) {};
|
||||
|
@ -30,16 +40,20 @@ window.WebPage = function() {
|
|||
if (typeof this.onConsoleMessage === 'function') {
|
||||
this.javaScriptConsoleMessageSent.connect(this.onConsoleMessage);
|
||||
}
|
||||
if (arguments.length === 1) {
|
||||
this.openUrl(arguments[0], 'get', this.settings);
|
||||
return;
|
||||
}
|
||||
if (arguments.length === 2) {
|
||||
this.loadStatusChanged.connect(arguments[1]);
|
||||
this.onLoadFinished = arguments[1];
|
||||
this.openUrl(arguments[0], 'get', this.settings);
|
||||
return;
|
||||
} else if (arguments.length === 3) {
|
||||
this.loadStatusChanged.connect(arguments[2]);
|
||||
this.onLoadFinished = arguments[2];
|
||||
this.openUrl(arguments[0], arguments[1], this.settings);
|
||||
return;
|
||||
} else if (arguments.length === 4) {
|
||||
this.loadStatusChanged.connect(arguments[3]);
|
||||
this.onLoadFinished = arguments[3];
|
||||
this.openUrl(arguments[0], {
|
||||
operation: arguments[1],
|
||||
data: arguments[2]
|
||||
|
|
|
@ -239,7 +239,7 @@ void WebPage::emitConsoleMessage(const QString &msg)
|
|||
void WebPage::finish(bool ok)
|
||||
{
|
||||
QString status = ok ? "success" : "fail";
|
||||
emit loadStatusChanged(status);
|
||||
emit loadFinished(status);
|
||||
}
|
||||
|
||||
void WebPage::openUrl(const QString &address, const QVariant &op, const QVariantMap &settings)
|
||||
|
|
|
@ -77,7 +77,7 @@ public slots:
|
|||
|
||||
signals:
|
||||
void loadStarted();
|
||||
void loadStatusChanged(const QString &status);
|
||||
void loadFinished(const QString &status);
|
||||
void javaScriptAlertSent(const QString &msg);
|
||||
void javaScriptConsoleMessageSent(const QString &msg);
|
||||
|
||||
|
|
Loading…
Reference in New Issue