如何在mysql结果中建立链接并单击时打开一个新窗口? [英] how to make a link in a mysql result and open a new window when clicked?
问题描述
我这里有使用 javascript 使mysql结果成为链接的代码.但是我的问题是,当我单击该链接时,它会打开一个新窗口,同时也会打开一个新选项卡.我只想要的是,当我单击链接时,它应该只会打开一个新窗口.
此处是代码.
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>";
}
}
}
?>
,这里是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')
}
如果要在新窗口中显示链接,请删除onclick
属性.您可以使用属性target
指定目标窗口.对于您来说,它设置为_blank
,这意味着在新窗口中打开链接"
所以改变:
echo '<td><a traget="_blank" onclick="pop_up(this)" href=VIEWSAMPLE.PHP?user_id='.$row["user_id"].'>'.$row["username"].'</a></td>';
收件人:
echo '<td><a target="_blank" href=VIEWSAMPLE.PHP?user_id='.$row["user_id"].'>'.$row["username"].'</a></td>';
实际上,Firefox,IE,Chrome,Safari等对属性target="blank"
具有不同的行为.
要将弹出窗口用作新窗口",请使用此行:
echo '<td><a onclick="pop_up(this)" href=VIEWSAMPLE.PHP?user_id='.$row["user_id"].'>'.$row["username"].'</a></td>';
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')
}
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>';
这篇关于如何在mysql结果中建立链接并单击时打开一个新窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!