0

Apologies if this question isn't worded very clearly. I'm working on a text-analysis visualisation and I have multiple HTML pages loading the same Processing sketch with p5.js. The only difference between the pages is that I need the sketch to load a different .txt file in setup() or preload() depending on what HTML page it is. The rest of the sketch remains identical.

How can I make my sketch load a different file (01.txt, 02.txt etc) depending on what page it's in? (book_one.html, book_two.html etc). Any help would be great, thank you!

themessup
  • 192
  • 14

1 Answers1

0

You can write JavaScript in p5.js, so the first thing I'd google is "JavaScript get current url" to see how to do that.

Here is the first result for that search, and it says you can get it like this:

window.location.href 

Now you just have to write p5.js code that uses this JavaScript variable. Maybe something like this:

function setup(){
    if(window.location.href == "http://example.com"){
       //load 01.txt
    }
    else{
       //loat 02.txt
    }
}
Community
  • 1
  • 1
Kevin Workman
  • 41,537
  • 9
  • 68
  • 107