Make each button, during the onclik event, trigger its own window?

Asked

Viewed 52 times

0

The following code will display several "tumbnails", where each has a button designated "tracklist". But it happens, for example, if I click one of the buttons and do not close the window, all other "tracklist" buttons that are "clicked" or activated will "write" in the first open window...

<head>
<script type="text/javascript">
function myFunction(content) {
    var playlist = content;    
    var x = parseInt((screen.width-800)/2);
    var y = parseInt((screen.height-600)/2);
    var win = window.open( '', 'pop', 'scrollbars=1,statusbar=1,menubar=0,resizable=1,width=800,height=600' ); 
    win.document.write ('Playlist:' + playlist); 
    win.moveTo(x,y);
}
</script>
</head>

PHP

foreach($rows as $row){
   echo "<div class='tumbnail'>";
   echo "<img src='imagem.jpg'>";
   echo "<input class=\"btn_tracklist\" type=\"button\" value=\"Tracklist\" onclick=\"javascript:myFunction('" . $row['tracklist'] . "')\"> </br>";                                
   echo "</div>";
 } /*END Foreach*/

1 answer

1


Modify the javascript. Instead of :

var win = window.open( '', 'pop', 'scrollbars=1,statusbar=1,menubar=0,resizable=1,width=800,height=600' ); 

use

var win = window.open( '', '_blank', 'scrollbars=1,statusbar=1,menubar=0,resizable=1,width=800,height=600' ); 

or set a different name for each window

See window open name parameter: http://www.w3schools.com/jsref/met_win_open.asp

Browser other questions tagged

You are not signed in. Login or sign up in order to post.