简体   繁体   English

我想打开一个新选项卡而不是弹出窗口

[英]I want to open a new tab instead of a popup window

I am trying to open a new tab. 我正在尝试打开一个新标签。 But Window.open() is opening up popup window. Window.open()正在打开弹出窗口。

I want to open hello.php file in a new tab. 我想在新标签中打开hello.php文件。 But it is opening up in a new popup window. 但它正在一个新的弹出窗口中打开。

<!DOCTYPE html>
<html>
<head>
<script language="javascript">

document.onmousedown=disableclick;
//status="Right Click Disabled";

function disableclick(event)
{
  if(event.button==2)
   {
     //alert(status);
     return false;    
   }
}
</script>
</head>
<body oncontextmenu="return false">

<form action="" method="POST" oncontextmenu="return false">



<b>Enter Username:</b><input type="text" name="username" value=""/><br>

<b>Enter Password: </b><input type="password" name="password" value=""/><br>

<input type="submit" value="submit" name="submit"/>
<input type="reset" value="reset" name="reset"/>

</form>

<?php


if (isset($_POST['submit'])) 
{

$username=$_POST['username'];
$password=$_POST['password'];

mysql_connect("localhost", "root", "") or die(mysql_error()); 

mysql_select_db("demo") or die(mysql_error()); 

$result=mysql_query("select * from employees where name='$username' and pass='$password'") 
 or die(mysql_error()); 


if(mysql_num_rows($result)==0)
{
print "<br/>";
print "<b>Incorrect Username/Password!!!</b>";
}
else
{


mysql_query("Create table $username(Question_No varchar(10),Selected_Answer varchar(10))") 
 or die(mysql_error());  


print "<br/>";
print "<b>Login successful!!!</b><br/><br/>";


print "<script>window.open('hello.php?username=$username')</script>";


print "<script>window.close('userdetails.php')</script>";
}

}
?>

</body>
</html>

In case it could be a javascript issue about override functions, do that: 如果它可能是关于覆盖函数的javascript问题,请执行以下操作:

<script>
(function(window, undefined){
    var win = window.open('your_url', '_blank');
    win.focus();
})(window);
</script>

That should make you can't use functions from other javascript code out of your function(window, undefined) wrapper- 这应该使你不能使用你的函数(窗口,未定义)包装器中的其他javascript代码的函数 -

你可以通过window.open(url, '_blank');来做到这一点window.open(url, '_blank');

assign the url to open to a tag's href attribute, with target="_blank", then trigger link click when you want. 指定url以打开标签的href属性,使用target =“_ blank”,然后在需要时触发链接单击。 Example: 例:

<a id="myLink" href="hello.php?username=<?php echo $username; ?>" target="_blank">

Then, call a js function to trigger link click 然后,调用js函数触发链接点击

document.getElementById('myLink').click();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM