tags:

views:

32

answers:

1

Hello,

Please go to http://musicalinstrumentsfinder.com/search.php

The top search box is a super search box if you will in that whatever text you type in it will automatically be put in the individual search boxes below. Also, upon clicking the "Search All" button, it will automatically simulate a click on all the individual search boxes below it.

To use it, please enter "Gibson" or "Fender" in the top search box.

Question: Upon clicking on the "Close Windows" button, how can I close the windows that were automatically opened?

Note that each window that automatically opens may have different URLs depending upon the key words entered in the top search form.

Also, the windows open from a HTML FORM action and not a JS window.open() command. I thus don't think that I can close them with a window.close() command

A: 

I think your only option would be to use window.open and .close ( saving the references to the windows ), as there aren't any references to the new windows/tabs that opened from the HTML form.

It shouldn't be that hard since you're using GET.

Edit: A snippet:

(function() {

var windowReferences = [], closeBtn = document.getElementById('close-btn'), form = document.getElementById('my-form');

form.onsubmit = function() {
    var urls = ['http://sitename.com?foo=bar', 'http://msn.com/foo/bar'], len = urls.length;
    for ( var i = 0; i < len; ++i ) {
         windowReferences.push( window.open( urls[i] ) );
    }
    return false;

};


closeBtn.onclick = function() {
    for ( var i = 0, l = windowReferences.length; i<l; ++i ) {
        windowReferences[i].close();
    }
}

})();

This hasn't been tested - lmk if it doesn't work.

meder
I am not sure I understand what you are saying.. Could you please explain in more details?Thanks a lot!
I'm saying you probably have to attach an event handler on the 'submit' event of the form element and manually do window.open for each url/ad, then push those window.open references into an array, on 'close windows' iterate through the array and invoke .close on each of the window object references.
meder