How to prevent “my own” javascript code to open a new window?

This one is hard

I have this task to build a module for a big system made with PHP. The most important rule is that I can’t touch the code of the core system, so I can’t fix some of it’s bugs.

The main service of my module is to create a custom document that is not edited by the system default editor, but by a custom form created by my module.

To prevent users from editing the custom document instead of filling the form, I can set the document to blocked at the time of creation.

But even with the document being blocked, the system opens its default editor in a new pop-up window, and then shows an incorrect error message that has nothing to do with the block, and it is messing with the users heads.

I could fix this in a minute by changing a few lines in the core code, but then I would loose my job. I also can’t ask the owner of the system to fix the problem because it would take forever (the owner is from a public institution).

The system function goes like this:

  1. When user creates document, it passes execution to a function on each module, so these modules could have the possibility to react to the document creation;
  2. The module receives data about the document created and checks if its type is the custom document type, then block it if true;
  3. The module passes execution back to code system, which finishes creating document (so I can’t use die() otherwise document isn’t created at all);
  4. The system open an editor so user can put content in it.

So I came with an idea that my module could, after blocking the document, output a javascript tag with code that would prevent javascript code created by the core system from using the command, or at least hide this pop-up.

Is there a way to do it with javascript?


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

You can overwrite the open if your code can run before the open occurs:

const myOpen =;
let iwanttopen = false: = function() {
  if (iwanttoopen) return myOpen(...arguments); // here YOU decide

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x