最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - I want to open a new tab instead of a popup window - Stack Overflow

programmeradmin7浏览0评论

I am trying to open a new tab. But Window.open() is opening up popup window.

I want to open hello.php file in a new tab. 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>

I am trying to open a new tab. But Window.open() is opening up popup window.

I want to open hello.php file in a new tab. 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>
Share Improve this question edited Sep 30, 2013 at 16:28 Jagger 10.5k11 gold badges57 silver badges96 bronze badges asked Sep 30, 2013 at 16:00 RedSunRedSun 1072 gold badges2 silver badges10 bronze badges 5
  • This is a browser settings issue. You can't do this with code. – Andy Commented Sep 30, 2013 at 16:02
  • 1 possible duplicate of JavaScript open in a new window, not tab or stackoverflow./questions/6296013/… – Mike B Commented Sep 30, 2013 at 16:02
  • which browser are you using? – Yatin Trivedi Commented Sep 30, 2013 at 16:04
  • I am using Google Chrome – RedSun Commented Sep 30, 2013 at 16:07
  • stackoverflow./questions/4907843/… – Andy Commented Sep 30, 2013 at 16:07
Add a ment  | 

3 Answers 3

Reset to default 10

In case it could be a javascript issue about override functions, do that:

<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-

You can do it by 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. Example:

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

Then, call a js function to trigger link click

document.getElementById('myLink').click();
发布评论

评论列表(0)

  1. 暂无评论