?
Solved

window.open popup works with IE and Epiphany, but not with Mozilla

Posted on 2005-04-01
4
Medium Priority
?
420 Views
Last Modified: 2008-03-06
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>
0
Comment
Question by:jarnold21
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 30

Expert Comment

by:third
ID: 13686969
i'm not sure what you're trying to accomplish but try

<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<script>
document.onkeyup=handleKeyPress;
function handleKeyPress(e)
{
     var keyCode=window.event?event.keyCode:e.which;
     var srcElement=window.event?event.srcElement:e.target;
     
     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>
0
 
LVL 30

Expert Comment

by:third
ID: 13686974
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>
0
 

Author Comment

by:jarnold21
ID: 13688858
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.
0
 
LVL 10

Accepted Solution

by:
ljo8877 earned 375 total points
ID: 13693518
Two issues in the code. One is that "which" is obsolete: you should use keyCode for both IE and Mozilla. Two, charCode is 0 for control (or non-character keys) and keyCode contains the 13. It is always 0 for keyDown and keyUp, Check the result of these events at this page:

http://lawrence.ecorp.net/inet/departments/samples/html/keycodes.html

I haven't encountered any difference in window.open between IE and Mozilla accept for the coordinate names. Try changing the window name from "test" to something else. Window.open will load the page in the named window if there is one open with that name.
0

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question