0

I´m building a application that takes a picture from the webcam in certain interval of time. Basically i'm calling a js function that takes the snapshot time to time,the js is triggered by a click event in a jsp page, to start the function.

Can i keep the js running when i´m switching between jsp pages? Is that possible?

  • 2
    Maybe https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage – luk2302 Jan 14 '19 at 14:37
  • 1
    Every page reload starts up a completely new `window` object, so no unless you create what's generally called a "single page application" and avoid complete page reloads. Or use local storage and implement your own "restart" functionality (see above comment). Might want to use session storage instead of local storage, depending on the application. – Pointy Jan 14 '19 at 14:37
  • 2
    You can use `ajax` or maybe `sockets`, or possibly using something to simulate persistence on the user's device, such as `localStorage` or `sessionStorage`, but I guess there's not a lot more you could do than what's been mentioned? Basically what @Pointy said, plus it does depend on **exactly** what you're trying to achieve here... – JO3-W3B-D3V Jan 14 '19 at 14:39

1 Answers1

0

A page reload resets the state.

Given the limited problem description, I would say use Ajax - define a button onclick event, in which take the picture then submit it via Ajax.

If you use a form-based upload, you can submit a form without reloading the page.

If this doesn't suffice have a look at How to upload photos using web app.

rustyx
  • 80,671
  • 25
  • 200
  • 267