Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Window.opener problem

Status
Not open for further replies.

keinloffel

Programmer
Mar 24, 2003
11
US
I have a main window which opens a pop up window.

I was trying to use window.opener to manipulate the parent window and met with some problems. So I did some error checking and put the following code in the popup:

<script>

mywin = window.opener

alert(mywin)

self.close()

</script>

The alert, shows undefined, because of which none of my window.opener implementations worked.

Do i need to define the windows?? Whats going on here?

By the way I'm using JSP, and it has js embedded in it.

Thanks!!

If you want to read throught the file, here it is:

<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;>
<html lang=&quot;en&quot;>
<head>
<meta http-equiv=&quot;content-type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
<meta http-equiv=&quot;refresh&quot; content=&quot;1800&quot;>
<title>Harland &copy;2003 | ITRBO | RBO Project Management | Enter New Project - Add Originator</title>
<script language=&quot;JavaScript1.2&quot; src=&quot;./lite.js&quot; type=&quot;text/javascript&quot;></script>
</head>

<body>
<%@ page language=&quot;java&quot; import=&quot;java.sql.*&quot;%>
<%@ page language=&quot;java&quot; import=&quot;java.util.*&quot;%>
<%@ page language=&quot;java&quot; import=&quot;java.text.*&quot;%>
<%@ page language=&quot;java&quot; import=&quot;com.harland.prj.*&quot; %>

<jsp:useBean id=&quot;prjb&quot; class=&quot;com.harland.prj.PrjBean&quot; scope=&quot;session&quot; />

<%
String projectID = request.getParameter(&quot;projectid&quot;) ;
if(projectID == null){
%>
<jsp:forward page=&quot;./prj_home.jsp&quot; />
<%}%>


<%
String originatoreit = request.getParameter(&quot;originatoreit&quot;);
String originatorcommon = request.getParameter(&quot;originatorcommon&quot;);
String originatorall = request.getParameter(&quot;originatorall&quot;);
%>


<% if(originatoreit != null){%>

<% if(originatoreit.equals(&quot;[Select Originator]&quot;)){%>
<script language=&quot;javascript&quot;>
window.alert(&quot;ERROR: Choose a valid Originator&quot;)
window.location=&quot;./prj_new_add_originator.jsp?projectid=<%= projectID%>&quot;
</script>
<%} else {%>
<script>

mywin = window.opener

alert(mywin)

self.close()
</script>


<% } %>
<% } else if(originatorcommon != null){%>

<% if(originatorcommon.equals(&quot;[Select Originator]&quot;)){%>
<script language=&quot;javascript&quot;>
window.alert(&quot;ERROR: Choose a valid Originator&quot;)
window.location=&quot;./prj_new_add_originator.jsp?projectid=<%=projectID%>&quot;
</script>
<%}%>

<%= originatorcommon%>
<%} else if(originatorall != null){%>

<%= originatorall%>

<%} else {%>
<script language=&quot;javascript&quot;>
window.alert(&quot;ERROR: Please Try Again&quot;)
window.location=&quot;./prj_new_add_originator.jsp?projectid=<%=projectID%>&quot;
</script>

<%}%>


</body>
</html>
 
keinloffel,

you're getting &quot;undefined&quot; when opening this page using window.open() from the parent? this error is to be expected if you open the window in any other way.

what browser / OS are you using?



=========================================================
while (!succeed) try();
-jeff
 
Where is the code that you use to open the popwindow? All of this code seems to be the popwindow itself...

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rich Cook
 
IE 5, Win2k.

My bad, I used <a href=&quot;popoup&quot; target=&quot;new&quot;>
and not window.open().

How can i write that with window.open() ?


Thanks

 
<a href=&quot;#&quot; onClick=&quot;window.open('myPage.htm','winName')&quot;>

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rich Cook
 
the example below will allow u to have a better control on the new window. enjoy it :)

<a href=&quot;javascript: cmdOpenWin('
function cmdOpenWin(url)
{
iWidth = 530;
iHeight = 400;
iOffset = parseInt((screen.availHeight - iWidth) * 0.6);
wOpenWin = window.open(url, &quot;wOpenWin&quot;,
&quot;toolbars=no,&quot; +
&quot;location=no,&quot; +
&quot;directories=no,&quot; +
&quot;status=no,&quot; +
&quot;menubar=no,&quot; +
&quot;resizable=no,&quot; +
&quot;scrollbars=yes,&quot; +
&quot;screenX=&quot; + ((screen.availWidth - iWidth) / 2) + &quot;,&quot; +
&quot;screenY=&quot; + iOffset + &quot;,&quot; +
&quot;left=&quot; + ((screen.availWidth - iWidth) / 2) + &quot;,&quot; +
&quot;top=&quot; + iOffset + &quot;,&quot; +
&quot;width=&quot; + iWidth + &quot;,&quot; +
&quot;height=&quot; + iHeight);
wOpenWin.focus();
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top