1
votes

I have here the code for making a mysql result a link using a javascript. But my problem is this, when i click that link it opens a new window and at the same time it also open a new tab. What i just want is that when i clicked the link it should only open a new window..can somebody please help me with it..

here the code..

public function dataview($query)
{

$stmt = $this->db->prepare($query );
$stmt->execute();

if($stmt->rowCount()>0)
{
while($row=$stmt->fetch(PDO::FETCH_ASSOC)) {
echo "<tr>";
echo "<td> ".$row['user_id']." </td>";
echo "<td> ".$row['username']." </td>";

echo '<td><a traget="_blank" onclick="pop_up(this)" href=VIEWSAMPLE.PHP?user_id='.$row["user_id"].'>'.$row["username"].'</a></td>';
echo "<td> ".$row['password']." </td>";

echo "</tr>";
 }
}
else
{
 echo "<tr>";
        "<td>Nothing here...</td>";
        "</tr>";
 }
}


}
?>

and here the javascript

function pop_up(url){
   window.open(url,'win2','status=no,toolbar=no,scrollbars=yes,titlebar=no,menubar=no,resizable=yes,width=800,height=600,directories=no,location=no') 
}
1

1 Answers

1
votes

If you want to have the Link in a new window yust remove the onclick-attribute. You can specify the target window with the attribute target. In your case it is set to _blank which means "open the link in a new Window"

So change:

echo '<td><a traget="_blank" onclick="pop_up(this)" href=VIEWSAMPLE.PHP?user_id='.$row["user_id"].'>'.$row["username"].'</a></td>';

To:

echo '<td><a target="_blank" href=VIEWSAMPLE.PHP?user_id='.$row["user_id"].'>'.$row["username"].'</a></td>';

Acutally Firefox, IE, Chrome, Safari and so on will have a different behaviour for the attribute target="blank".

To use a popup as a "new window" use this line:

echo '<td><a onclick="pop_up(this)" href=VIEWSAMPLE.PHP?user_id='.$row["user_id"].'>'.$row["username"].'</a></td>';