Popup windows seperately for each button

Viewed 28

I created several buttons which share the same class .custom_button. Clicking the button will popup a new window to show some data. The problem is that all these buttons are linked to the same window even I assign different target url for each button. For example, there 3 buttons {A, B, C}, clicking A creates a window X with url localhost:8080/button/a. If I click B, the data will be sent to the window X with url localhost:8080/button/b. However, what I want is to display the result of B in another window Y. Here is my js code. Could anyone help on this?

$(document).ready(function(){
   $(".custom_button").on( {
       mousedown: function (event) {
           if( event.which <= 2 ) {
               var button_id = this.id,
                   button_href_id = "#" + button_id + "-href";
               event.preventDefault();
               window.open($(button_href_id).attr("href"), "popupWindow", "width=1400,height=900,scrollbars=yes");
           }
       }
   });
});
2 Answers

When changing popupWindow to _blank you open a new window on every click. So if you click "Button A" twice, you get two windows with the same content. Try to give your window a unic name. Something like this:

window.open($(button_href_id).attr("href"), button_id, "width=1400,height=900,scrollbars=yes");

This way you trigger the same window for the button.

The problem is solved. Just changing the "popupWindow" parameter to "_blank" will achieve what I want.

Related