Skip to main content
daniellieske
Known Participant
November 3, 2020
Question

Interaction between website and HTML5 canvas

  • November 3, 2020
  • 2 replies
  • 299 views

I'm wondering if someone could provide me some keywords in order to research the possibilities of interaction between a website and an embedded HTML5 canvas. What I'm specifically looking for is to start an animation on a specific frame instead of having it start on the first frame. In my naive imagination I'd have a piece of code on the website that on load tells the HTML5 canvas element on which frame to start. How would you go about something like this? 

 

Any help is appreciated!

 

-DanieL

This topic has been closed for replies.

2 replies

kglad
Community Expert
Community Expert
November 3, 2020

you're welcome.

kglad
Community Expert
Community Expert
November 3, 2020

you could open your canvas file using a query string that indicates the starting frame:

 

from your non-animate page link to your animate page and pass the query string. eg,  animate_page.html?startframe=12&var1=whatever&var2=whateverelse

 

 

in animate:

 

var startframe = parseQueryStringF("startframe");
var var1 = parseQueryStringF("var1");
var var2 = parseQueryStringF("var2");

 

function parseQueryStringF(varname) {
var queryA = window.location.search.substring(1).split("&");
for(var i=0;i<queryA.length;i++){
if(varname==queryA[i].split("=")[0]){
return queryA[i].split("=")[1];
}
}
return null;
}

 

 

 

 

daniellieske
Known Participant
November 3, 2020

Thanks for your quick reply! I'll give that a test!