r/AskProgramming • • 16m ago

Javascript How to focus a parent window from a child window?

To specify, I am a beginner in javascript, so I apologize if I cannot understand any terminology.

I want to state the limitations I working in currently. I am writing vanilla JS into the in-built text editor on a chromebook, (ChromeOS version 150.0.7871.222). The JS is running in chrome. The reason why is because this is a school-issued computer, and I want to produce something that can work within those limitations. JS, CSS, and HTML are the only coding languages I know that be ran in a Chrome and edited from a text editor.

I want to create a little game where I can move a window around the screen. The reasons for making this using windows is for the meta-narrative of the game.

I understand for it to move or to be focused, it must have user activation via an IsTrusted bool turning on from an event like a button click.

I have made the basic movement code, but then I came onto a massive issue. I cannot move multiple windows without having them all being unfocused at the same time and letting them go underneath the parent Window. I have spent countless hours perusing forums, Stack Overflow, and MDN. Many of the solutions have not worked. I cannot call a function from the parent window to focus itself. I cannot focus using the opener method. Post message does not work. Calling it from inside an onblur event does not work. Putting these things in user activated functions also does not work.

Is there any way I can do this, or is this just another limitation that I need to work around?

0 Upvotes

0 comments sorted by