0
votes

i create table who has link to post data, then if the link clicked, it will open in new window with the size we want.

here's the code :

while($row = mysqli_fetch_array($result))
            {
            echo "<tr>";
            echo "<td>" . $row['PONumber'] . "</td>";
            echo "<td>" . $row['POdate'] . "</td>";
            echo "<td>" . $row['customername'] . "</td>";
            echo "<td>" . $row['description'] . "</td>";
            echo "<td>" . $row['poqty'] . "</td>";
            echo "<td>" . $row['TotalQtySpb'] . "</td>";
            echo "<td>" . $row['OTSPO'] . "</td>";?>
            <td><?php echo('<a href="index.php?action&ponumber='.$row['PONumber'].'" target="_blank">'."Klik Disini".'</a>');?></td><?php
            echo "</tr>";
            }

i tried to modify open in new window by add target="_blank" in a href but its not working (opened in new tab instead in new window)..

tried javascript like this but didnt understand how to apply it in table.

<button onclick="myFunction()">Try it</button>

    <script>
    function myFunction() {
        window.open("http://www.w3schools.com","","width=900,height=300,top=100,left=100" );
    }
    </script>
2
when you say "it is not working", what do you see? did you check your pop up blockers? - hdlopez
no reason that target="_blank" shouldn't work - charlietfl
it working but it opened in new tab, not in new window. - Gusti Aldi
You can't open new window from href. Would need to pass the href to window.open and prevent the default click opening new tab - charlietfl

2 Answers

0
votes

Something like this should get you going (untested, just for e.g.):

PHP:

$result = do_your_mysqli_query_here;

$out = '';
while($row = mysqli_fetch_assoc($result))
{
    $out .= "<tr>";
    $out .= "<td>" . $row['PONumber'] . "</td>";
    $out .= "<td>" . $row['POdate'] . "</td>";
    $out .= "<td>" . $row['customername'] . "</td>";
    $out .= "<td>" . $row['description'] . "</td>";
    $out .= "<td>" . $row['poqty'] . "</td>";
    $out .= "<td>" . $row['TotalQtySpb'] . "</td>";
    $out .= "<td>" . $row['OTSPO'] . "</td>";
    $out .= '<td><a class="porow" href="#" data-ponumber="'.$row['PONumber'].'" target="_blank">Klik Disini</a></td>';
    $out .= "</tr>";
}
echo $out;

javascript/jQuery:

$(document).on('click', 'a.porow', function(){
    var po = $(this).data('ponumber'); //gets value of data-ponumber for this a tag
    var str = 'http://index.php?action=&ponumber=' + po;
    window.location.href = str;
});
0
votes

Can do it this way using jQuery

$('td a').click(function(e){
      // prevent browser following link
      e.preventDefault();
      //open in new window
      window.open(this.href,"","width=900,height=300,top=100,left=100" );
});

Add a class to elements and update the selector with that class