There is this ecommerce platform that uses a lot of ajax. In the backoffice order section there are two possibilities: order list page and detail order page. The url doesn't change, it would be easy if it did to tell in which page i am but it is not the case.
This platform use ajax to assign to a variable some value, with this value I can tell in my code in which page I am, the best I could do is use setInterval()
to get the change in this variable. I hate using setInterval()
so I am looking into alternatives.
Why do i hate it? Imagine a client that uses our "help" in this ecommerce and leave it open all day. setInterval()
is hateful in this situations.
The thing is that I don't have any control in this external Javascript that the platform runs so I need a way to use some kind of listener to this variable.
The best I could find is this Akira's answer but I can't use it because this variable is not in my control to define.
This is what I did:
setInterval(function() {//get the variable from the source code of the platform; it changed? do stuff}, 1000);
Do you know a better way to do it than setInterval()
? Just to improve my code.
Edit: this variable is in a script, not in an html element
Edit 2: this link is somewhat a better way than setInterval()
, basically an improved setInterval()
because you can tell him how many iterations to do, and this is okay in the case the client leave open the platform all day long, but to use it I need something to detect the client did some activity on the page, what do I need for this? A listener soooo, back to square one