新标签中的Javascript打开链接[重复]

时间:2022-05-04 21:16:50

This question already has an answer here:

这个问题在这里已有答案:

Hi I have this javascript code that works fine. It is a dropdown menu that selects employee's name. Then it will automatically direct to leave_approve_process.php that will display any related information about the employee.

嗨,我有这个javascript代码,工作正常。这是一个选择员工姓名的下拉菜单。然后它会自动指向leave_approve_process.php,它将显示有关该员工的任何相关信息。

However, how can I change the code so that it will open leave_approve_process.php in a new tab. Please help me as I'm new to this javascript. Thanks.

但是,如何更改代码以便在新选项卡中打开leave_approve_process.php。请帮助我,因为我是这个javascript的新手。谢谢。

$employee = mysqli_query("SELECT * FROM employee");

<script type="text/javascript">
function showUser()
{
    var str1=document.getElementById('employee').value;
    if (str1=="")
    {
        document.getElementById("txtHint").innerHTML="";
        return;
    } 
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
        xmlhttp.onreadystatechange=function()
    {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
            document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
        }
    }
    xmlhttp.open("GET","leave_approve_process.php?id="+str1,true);
    xmlhttp.send(); 
}
</script> 

<form name="form2" id="form2" method="post" action="">
<select name="employee" id="employee" onChange="showUser()" class="validate[required]">
    <option value="">Select one</option>
    <?php
    while($row_sem=mysqli_fetch_array($employee))
    {       
        echo "<option value='". $row_sem['emp_id'] ."'>". $row_sem['emp_name'] ."</option>";        
    }
    ?>
</select>
</form>
<br />
<div id="txtHint" align="center"></div>

1 个解决方案

#1


1  

Create a new function and call it from within your current function.

创建一个新函数并从当前函数中调用它。

function OpenInNewTab("leave_approve_process.php?id="+str1,true) {
  var win = window.open("leave_approve_process.php?id="+str1,true, '_blank');
  win.focus();
}

You can find more relevant answers at Open a URL in a new tab (and not a new window) using JavaScript if my answer didn't work for you.

如果我的答案不适合您,可以使用JavaScript在新选项卡(而不是新窗口)中打开URL找到更多相关答案。

#1


1  

Create a new function and call it from within your current function.

创建一个新函数并从当前函数中调用它。

function OpenInNewTab("leave_approve_process.php?id="+str1,true) {
  var win = window.open("leave_approve_process.php?id="+str1,true, '_blank');
  win.focus();
}

You can find more relevant answers at Open a URL in a new tab (and not a new window) using JavaScript if my answer didn't work for you.

如果我的答案不适合您,可以使用JavaScript在新选项卡(而不是新窗口)中打开URL找到更多相关答案。