Forum Moderators: open

Message Too Old, No Replies

AdX banner steals focus from textarea

         

csdude55

9:16 pm on Mar 18, 2017 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I recently signed on with a company that's using Google Ad Exchange (AdX) instead of my regular Adsense account.

But every once in awhile, a banner will start to load that constantly shifts focus from the input field that the user is using. Which is VERY irritating! Imagine that you're typing a sentence, then all of a sudden the cursor goes away, mid-word. So you have to click back into the field, start typing, and it goes away again. Over and over.

I can't just consistently force the focus to be on one input field, because (1) there are at least 2 potential input fields, and (2) the user would want to click on emojis, the "Submit" button, or other things on the page (like an ad). So I'm trying to find a way to make the focus stay where the user last placed it, unless the event is a click, tab, or whatever event is called on a mobile device when you press on something.

I'm guessing that it's going to look something like:

<script>
// at the top of the page
document.addEventListener("some_event", function(e) {
if (e.stopPropagation) e.stopPropagation();
e.cancelBubble = true;
}, false);</script>


But what would the event be? Is there a way to find what event is happening during this period?

csdude55

12:44 am on Mar 19, 2017 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Furthering...

I think the event I'm looking for is "onfocusout". So I think I'm getting closer with:

document.addEventListener("onfocusout", function(e) {
if (
// function does not equal 'click'; I think this catches 'touch' events, too
e != 'click' &&

// function is not the user pressing 'tab'
e.onkeydown != '[whatever the keycode is for "tab"]' &&

// the browser actually recognizes the stopPropagation() function
e.stopPropagation
) {
e.stopPropagation();
e.cancelBubble = true;
}
}, false);


I'm almost positive that my use of "e" in that is all kinds of wrong, but I hope you see where I'm heading. What would be the correct way to code it?