var wpage =require('webpage').create();
wpage.onPageCreated=function(newpage){
console.log("Entering in onPageCreated callback");
console.log(newpage.url);}
wpage.open('http://localhost/tasks/newwindow.html',function(status){
console.log(status);});
JavaScript
newwindow.html
<html><head><title>Welcome to phantomjs</title></head><body><scripttype="text/javascript">
window.onload =function(){
window.open("test.html","window1");}</script><h1>This is a test page</h1></body></html>