0

I want to open a page with javascript window.open() and i want to check if that page is opened in a window before just bring it to front and if that page not opened before open it with a new window.

I am making a music player and i want to add it to pages in my site. when a user click "open player" button it will open the player popup window. but it was opened by the user before when button clicked it would be bring that opened window rather than opening a new window.

Any javascript or jquery solutions are there?

This is the function i using to open new window.

function popUp() {
        window.open("popup_player.php", "_blank", "toolbar=yes,scrollbars=yes,resizable=yes,top=500,left=500,width=400,height=400",true);
    }
Lahiru Madusanka
  • 270
  • 2
  • 13
  • 2
    http://stackoverflow.com/questions/34217653/html-javascript-navigate-to-an-already-opened-browser-tab-window – rejo Jul 15 '16 at 05:33
  • http://stackoverflow.com/questions/31605570/how-to-check-if-page-is-loaded-for-the-first-time-using-javascript – Ranjan Jul 15 '16 at 05:37
  • This questions not have my wants and answers. – Lahiru Madusanka Jul 15 '16 at 05:51
  • Does't specifying name of the window (instead of `_blank`) cause all click to open the link in the same window every time (and create the window if it doesn't exist)? However it would reload the player URL on each click. – Marki555 Jul 15 '16 at 09:06
  • https://stackoverflow.com/questions/2438304/what-is-name-parameter-in-window-open – Marki555 Jul 15 '16 at 09:07
  • is there a way to pass a data like file name and store it in a array and if a user add more than a one song that array have to add that song and keep other data? (playlist) – Lahiru Madusanka Jul 15 '16 at 10:29

1 Answers1

1

If you give the window a name (the second argument), on the second call window.open will just focus the window rather than opening a new one. So:

window.open(yourUrl, "aWindowName");

The browser may reload the window on the second open. If you don't want that, you can use a blank URL:

var wnd = window.open("", "aWindowName");
if (!wnd.location.hostname) {
    wnd.location = yourUrl;
}
T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
  • I'm using a function and i'm calling all of window.open inside that function. how do i do that to that function. i'm goner update question with that function now. – Lahiru Madusanka Jul 15 '16 at 05:38