0

There is a website which fires a function on when the tab is blurred. I don't want that to happen.
Is there a way I can stop javascript from firing window.onBlur event?
From initial search, I have come to the conclusion that I need to override the default function of javascript, which can be done using userscript managers like Greesemonkey.
I tried the following script in Greesemonkey:
window.onblur = null
This doesn't seem to have any effect and the webpage behaves same as previously.

6
  • if it's just for you, you can set an event breakpoint in devtools. you can also edit the js in devtools, running the site off your patch once you locate the event handler in code. Commented Nov 2, 2018 at 16:52
  • 2
    You've rejected userscript managers with no explanation of why you're unable to use them, when this is the solution you should use. You can't edit the script of an arbitrary page without some kind of plugin that allows you to inject script. Commented Nov 2, 2018 at 16:53
  • @meagar: chrome let's you do just that in devtool's sources tab. new since 67-ish iirc Commented Nov 2, 2018 at 16:55
  • @meagar the language of question wasn't clear enough. I do not know how to do it using user script manager too. Please have a look at edited question. Commented Nov 2, 2018 at 17:20
  • No. It's impossible to do this (automatically) without an extension. You have to either use Tampermonkey or write your own extension. The question also needs a minimal reproducible example and/or a link to the target page. Commented Nov 2, 2018 at 18:37

1 Answer 1

2

Have look at Event.preventDefault() and Event.stopPropagation() if it helps your case.

If you would like to override the function which is called on the event, you can simply redefine it and insert it using a script manager. For example:

var originalCallbackFunction = callbackFuntion;
callbackFunction = function() {    // Redefinition
    /* Do something else */
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.