Reputation: 9094
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:
die()
otherwise document isn't created at all);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 window.open()
command, or at least hide this pop-up.
Is there a way to do it with javascript?
Upvotes: 2
Views: 81
Reputation: 177786
You can overwrite the open if your code can run before the open occurs:
const myOpen = window.open;
let iwanttopen = false:
window.open = function() {
if (iwanttoopen) return myOpen(...arguments); // here YOU decide
}
Upvotes: 4