jonas jonas - 7 months ago 50
Javascript Question

How to remove all event listeners from window.top once any of them is first tiggered?

<script type="pseudo">
window.top.mousemove || window.top.ontouchstart = setTimeout(action(), 60000);
window.top.removeEventListener(ALL****);
</script>


please correct into working JS.


  • It is unnecessary to keep listening the whole session long once first event happened.

  • It can't be like ...body onClick=(setTimeout... but must be about window.top because it is a frame referring to whole page.


Answer
var listener = function(callback)
{ 
  window.top.removeEventListener("mouseover",listener);
  window.top.removeEventListener("ontouchstart",listener);
  setTimeout(function(){//your action function code},6000);
}

window.top.addEventListener("mouseover",listener);
window.top.addEventListener("ontouchstart",listener);

I hope it will help you.