-1

Tell me if this makes any sense. I have been accessing a website through a popup window for years. using

window.open('https://example.com',mypopup,parameters);

I click a button in my main window, and it pops up that page. other buttons on my page take me to different pages on the site in the same popup window, like this...

window.open('https://example.com/page2.html',mypopup,parameters);

Nothing has changed in my program, but the website stopped allowing this. Is that possible? I thought it could be something with my browser, but no. All browsers no longer work.

Now, the popups are appearing in different windows and all functions like mypopup.focus() and mypopup.close() seem to have no effect. It's as if the name mypopup is no longer recognized and it's just creating new unnamed windows.

Could example.com have added some kind of security to not allow access the way I used to? Nothing changed on my end.

4
  • 1
    There's your answer: "the website stopped allowing this". You can't fix this, other than by contacting the site operators and asking if they'll change it back. Commented Jul 3 at 1:52
  • The thing is, I can still get to all the pages in a popup. They are just all separate popups and seem to be unnamed. Seems like a strange thing for a website to disable. Commented Jul 3 at 1:55
  • @TangentiallyPerpendicular That's incorrect. The OP isn't accessing the windows in a standard way and it's possible the web host simply stopped supporting that legacy non-standard approach. Using the correct technique (see my answer below) cannot stop being supported because it's using standard ECMAScript and the standardized aspects of window. Commented Jul 3 at 3:32
  • "but the website stopped allowing this. Is that possible?" - all the website has to do, is assign its own window/tab a different name, via window.name = "xyz", which will overwrite the name you gave it from your end.
    – CBroe
    Commented Jul 3 at 6:36

1 Answer 1

0

The correct way to reference another window is to capture a reference to it in a variable upon opening it. The following code won't work here in Stack Overflow due to sandboxing, but it will work in the real world.

document.querySelector("#btn").addEventListener("click", newWin);

function newWin(){
  let myPopUp = window.open("http://example.com");

  // Then you work with the variable
  myPopUp.focus();
  myPopUp.close(); 
}
<button id="btn">Click Me</button>

Giving the window a name as an argument is the way to be able to target content to that window, but not the standard way to access the window that houses that content from JavaScript.

Not the answer you're looking for? Browse other questions tagged or ask your own question.