javascript - Phantomjs as Client: Handle new tab -


a quite similar case handled on page here problem focused using phantomjs server.

my problem is, use phantomjs client. during code executed new tab opened. @ moment handle following way. here first initialization of webpage:

var page = new webpage();  page.onconsolemessage = function(msg) {     console.log(msg); };  page.onloadstarted = function() {     loadinprogress = true; };  page.onloadfinished = function() {     loadinprogress = false; };  page.onurlchanged = function(targeturl) {     console.log('new url: ' + targeturl); }; 

now handle second page implemented onpagecreated handler this:

page.onpagecreated = function(new_page){     new_page.onconsolemessage = function(msg) {       logger.log(msg);     };      new_page.onloadstarted = function() {       loadinprogress = true;     };      new_page.onloadfinished = function() {       loadinprogress = false;      };     page = new_page; }; 

the problem is, of course works once, because new page assigned old 1 not implement onpagecreated method again.

question: there way in different more elegant way? saw in documentation, there property called pages documentation quite bad there. possible switch main frame on working new tab , close old tab without changing whole page element @ moment?

something (pseudocode)

page.onpagecreated = function(new_page){     //page.mainframe = new_page.mainframe;     //or     //page.gotonexttab(); } 

additional question additional problem is, not seem work, if initialize page again, did in first code snippet. seems me there garbage collected while should not garbage collected.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -