00:00
00:00
Newgrounds Background Image Theme

Chan99 just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

on window blur, focus on window

854 Views | 2 Replies
New Topic Respond to this Topic

on window blur, focus on window 2019-04-18 13:26:06


javascript jquery


I've got an iframe. I'm tracking if it's been clicked in using the blur method

var overiFrame = -1;
$('iframe').hover( function() {
    overiFrame = $(this).closest('.banner').attr('bannerid');
}, function() {
    overiFrame = -1
});
$(window).blur( function() {
    if( overiFrame != -1 ){
        seconds = 0; 
    }
});


This tracks the click, because now the window has been blurred.


The problem is, additional clicks aren't tracked and therefore resetting the seconds to 0.

Maybe I can refocus after it is set to 0, so that it can be blurred again.


If I switch out the seconds = 0, for an alert, the alert never stops firing (which is good) because the alert refocuses the window outside of the iframe and it is no longer blurred.


I've tried $("window").focus(), but that doesn't work.


What other options do I have?


Cheers,

Response to on window blur, focus on window 2019-04-22 16:38:20


@Diki ?

Maybe you know the answer? Or can find it because I'm sure you'd be able to find the answer better than me.


At 4/22/19 04:38 PM, Aprime wrote: @Diki ?
Maybe you know the answer? Or can find it because I'm sure you'd be able to find the answer better than me.


Hey,


Sorry about a slow response. I've been busy.


I'm not really sure what it is you're trying to do. (That 'seconds' variable isn't declared in your snippets, so I don't know what it's for.) If all you want to do is track which iframe the mouse cursor is over, you only need the mouseenter/mouseleave events. This JS code would work:


function onEnterIFrame(iframe, event) {
  console.log("Entered Frame:", iframe.id);
}


function onExitIFrame(iframe, event) {
  console.log("Exited Frame:", iframe.id);
}


Array.prototype.forEach.call(
  document.body.querySelectorAll("iframe"),
  function(itr) {
    itr.addEventListener("mouseenter", onEnterIFrame.bind(null, itr));
    itr.addEventListener("mouseleave", onExitIFrame.bind(null, itr));
  }
);

Here's a working example of that: https://tystuff.com/if.html


If that doesn't work, I'd need a bit more information regarding what it is you're trying to do.