jarnold21
asked on
window.open popup works with IE and Epiphany, but not with Mozilla
I can't get window.open to work right with Mozilla even though it works fine with IE (Windows XP) and Epiphany (X Windows). By "working right" I mean that the URL I call with window.open will popup on the working browsers. On Mozilla the new URL appears in the same browser, removing the page that executed window.open.
The following code replicates the problem I described. The purpose of the code is to open a popup when I enter the <Enter> key inside the text field:
<html>
<head>
<script language=javascript>
function handleKeyPress(evnt)
{
var keyCode = evnt.keyCode ? evnt.keyCode : evnt.which ? evnt.which : evnt.charCode;
if(keyCode == 13)
{
window.open("http://www.google.com","test");
return false;
}
return true;
}
</script>
</head>
<body>
<form action=index.php method=post>
<input type=text name=myval onkeypress="return handleKeyPress(event);">
<input type=submit>
</form>
<script>
window.open("http://www.google.com","test");
</script>
</body>
</html>
The following code replicates the problem I described. The purpose of the code is to open a popup when I enter the <Enter> key inside the text field:
<html>
<head>
<script language=javascript>
function handleKeyPress(evnt)
{
var keyCode = evnt.keyCode ? evnt.keyCode : evnt.which ? evnt.which : evnt.charCode;
if(keyCode == 13)
{
window.open("http://www.google.com","test");
return false;
}
return true;
}
</script>
</head>
<body>
<form action=index.php method=post>
<input type=text name=myval onkeypress="return handleKeyPress(event);">
<input type=submit>
</form>
<script>
window.open("http://www.google.com","test");
</script>
</body>
</html>
but this simple code does the same thing,
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<script>
function newWindow(){
window.open("http://www.google.com","test");
return false;
}
</script>
</head>
<body>
<form action=index.php method=post onsubmit="return newWindow();">
<input type=text name=myval>
<input type=submit>
</form>
</body>
</html>
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<script>
function newWindow(){
window.open("http://www.google.com","test");
return false;
}
</script>
</head>
<body>
<form action=index.php method=post onsubmit="return newWindow();">
<input type=text name=myval>
<input type=submit>
</form>
</body>
</html>
ASKER
I appreciate the last two answers, but I the advice because I need to react to the <Enter> key from the text field. The interface that I'm developing has many text fields and each one directs the focus another field depending on the data input before the <Enter> key is pressed.
I guess the bottom line of my question is: Is there a problem, or something that I need to watch for, when executing window.open inside a JavaScript function that is executed as a result of onKeyPress? This question specifically refers to the Mozilla browser. I have absolutely no problem with IE, but I need to get my interface to work with Mozilla too.
I guess the bottom line of my question is: Is there a problem, or something that I need to watch for, when executing window.open inside a JavaScript function that is executed as a result of onKeyPress? This question specifically refers to the Mozilla browser. I have absolutely no problem with IE, but I need to get my interface to work with Mozilla too.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<script>
document.onkeyup=handleKey
function handleKeyPress(e)
{
var keyCode=window.event?event
var srcElement=window.event?ev
if(keyCode==13 && srcElement.form)
{
window.open("http://www.google.com","test");
return false;
}
return true;
}
</script>
</head>
<body>
<form action=index.php method=post onsubmit="return false;">
<input type=text name=myval>
<input type=submit>
</form>
</body>
</html>