在新窗口中打开的链接,其大小与我们在href中所需的大小相同

时间:2016-06-08 01:19:48

标签: javascript jquery html

我创建了一个包含发布数据链接的表,然后如果链接被点击,它将在新窗口中以我们想要的大小打开。

这是代码:

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>";
            }

我试图通过在href中添加target =“_ blank”来修改open在新窗口中但是它不起作用(在新窗口中打开而不是在新窗口中打开)..

试过像这样的javascript但是不明白如何在表格中应用它。

<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 个答案:

答案 0 :(得分:0)

Something like this应该让你去(未经测试,只是为了例如。):

<强> 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;
});

答案 1 :(得分:0)

可以使用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" );
});

向元素添加类并使用该类更新选择器