The child lost its parent!!
I have a parent window, when somebody clicks on an image a JS popup opens and displays the photo and its information.
To close the popup/child window, and to flash an element on my parent/opener window, I have been using this function:
function closeWindow() {
var currentID = document.getElementById('currentID').value;
window.opener.flashElement(currentID);
window.close();
}
My problem is this doesn't work if my users navigate away from the page that the popup originally opened. For example, in the popup window, there are next and previous buttons to scroll through the individual photos in that set of results, which reloads the page with a new querystring value.
If my user scrolls (reloads page) less than 7 times it's okay but if they scroll more than that, the window.opener
function does not work, and because of that, the window.close
function doesn't either!
I could probably rebuild the page so the data comes via an AJAX call, rather than reloading the page, but that's a lot of work I could do without.
Any ideas?
My guess is that
window.opener.flashElement(currentID);
is throwing an error, or the function does not exist. Most likely the element with the value of currentID does not exist on the page. Try catching the error.
function closeWindow() {
var currentID = document.getElementById('currentID').value;
try {
window.opener.flashElement(currentID);
} catch (err) {
alert(err.description || err) //or console.log or however you debug
}
window.close();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With