N
N
nektobit2016-02-02 03:24:26
CMS
nektobit, 2016-02-02 03:24:26

js and backspace. How to disable script re-execution?

We have a situation:
1. The page is loaded - the inline js code is loaded along with it.
2. The code should be executed once, and it is executed.
3. The user leaves the page.
4. User returns to pages with backspace! The script will be executed a second time...

I can't use cookies, I need the script to work on devices without cookies. write to db? Ajax?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
Yuri, 2016-02-02
@nektobit

as I already wrote, there will be no sessions without cookies, so it’s useless to make ajax requests, you still won’t understand that 2 requests came from one client.
use the samy.pl/evercookie library, which tries to save data on the client in all conceivable ways, including localStorage and all sorts of browser caches.
used for cases when you still need to track the user, even if he clears cookies.
the number of ways is amazing
- Standard HTTP Cookies
- HTTP Strict Transport Security (HSTS) Pinning
- Local Shared Objects (Flash Cookies)
- Silverlight Isolated Storage
- Storing cookies in RGB values ​​of auto-generated, force-cached
PNGs using HTML5 Canvas tag to read pixels (cookies) back out
- Storing cookies in Web History
- Storing cookies in HTTP ETags
- Storing cookies in Web cache
- window.name caching
- Internet Explorer userData storage
- HTML5 Session Storage
- HTML5 Local Storage
- HTML5 Global Storage
- HTML5 Database Storage via SQLite
- HTML5 IndexedDB
- Java JNLP PersistenceService
- Java CVE-2013-0422 exploit (applet sandbox escaping)
although of course in 99.9% of cases cookies will still be used, rarely if they are turned off.

D
Dave, 2016-02-02
@djay

Yes AJAX + Session on the server side:
Before executing inline JS code, make an Ajax request and see if the session has the value active = true. If not, then you execute the code, and then you immediately send another request that writes active = true to the session.
Look like that's it. Now it doesn't matter if the user clicked backSpace or not, the code will be executed only once.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question