Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Multiple page.open in Single Script

Tags:

People also ask

Can I use one JavaScript file for multiple HTML pages?

You can store one or more of your JavaScript scripts in a single . js file and access them from multiple HTML pages. Put the script in an external JavaScript file. If you have the script already inside your HTML page, remove all the JavaScript code inside the <script> tag and paste it into a separate file.

How do I put multiple pages in one HTML file?

page=pagename ) URL parameter determines which page content to serve. Show activity on this post. Twine is an open-source tool for telling interactive, nonlinear stories. It generates a single html with multiples pages.

Does each HTML page need its own JS file?

In case all html pages use separate javascript files, its better to keep them separate. Based on users action they will be cached on browser end.

How do I open multiple urls in HTML?

You can try this in the anchor tag. Where in anchor tag use onclick method with the open method. Define both links using the open method, it will open two links with one click.


My goal is to execute PhantomJS by using:

// adding $op and $er for debugging purposes exec('phantomjs script.js', $op, $er); print_r($op); echo $er; 

And then inside script.js, I plan to use multiple page.open() to capture screenshots of different pages such as:

var url = 'some dynamic url goes here'; page = require('webpage').create(); page.open(url, function (status) {     console.log('opening page 1');       page.render('./slide1.png');             });  page = require('webpage').create(); page.open(url, function (status) {     console.log('opening page 2');       page.render('./slide2.png');         });  page = require('webpage').create(); page.open(url, function (status) {     console.log('opening page 3');       page.render('./slide3.png');             phantom.exit(); //<-- Exiting phantomJS only after opening all 3 pages }); 

On running exec, I get the following output on page:

Array ( [0] => opening page 3 ) 0 

As a result I only get the screenshot of the 3rd page. I'm not sure why PhantomJS is skipping the first and second blocks of code (evident from the missing console.log() messages that were supposed to be output from 1st and 2nd block) and only executing the third block of code.