myth024 myth024 - 4 years ago 143
Javascript Question

Detecting open window on load

I apologize if the answer is posted elsewhere.
I have a function.

function RPop() {'/live365', 'live365', ',width=400,height=550,resizable=yes,scrollbars=no,menubar=no');
return true;

This function works as intended. The div goes poof and a pop up window opens when a user clicks a link. The pop up window and the div both have radio players so If someone refreshes the page, the removed div shows back up again. I figure the simplest solution is to check to see if the window named live365 is open and if it is, then remove the div automatically. The problem is that everyone keeps writing out these complex functions that check this and do that when all I really need is something to check if the window is open or exists. I can figure out how to do the rest.
I know the following is programmatically incorrect but I'm thinking along these lines.

$(document).ready(function () {
if window.live365 = open; {

I think that SHOULD work or something close to it. I also considered setting a cookie, or using the HTML5 session thing. Ultimately, I've seen several sights use media players that will pop out into a window and I'm attempting to duplicate that effort in my own way.

Answer Source

Go Here: How do I use javascript or jquery to check if named window exists

The entire goal of this project was to provide users visiting a page the option to open a streaming audio source in it's own window and clear the one on the current page. As indicated by my original question this was successful. The problem then came if the user refreshed the page because it would end up playing the same audio from two different sources. After learning more jquery and javascript I came back to once again attack this issue. I, however came at it from a different angle and ended up answering this question at the same time. The end result was using local storage to store a numeric value.

 window.localStorage.radioOut = "1"

adding this to the window that actually got popped out:

window.addEventListener("beforeunload", function (event) {
  window.localStorage.radioOut = "0"

And then adding this into the footer of the site:

if (window.localStorage.radioOut === "1") {

If you follow the link to the post there is more detail there. In the end this allowed me to put the radio player on multiple pages and have them not show up if there was currently a popped out version running. Thank you all for providing me some direction that allowed me to continue to research and finally find a solution I was happy with.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download