[Javascript] Popup window stumper

FERON Matthieu FERONMA at cic-i.com
Mon Dec 17 11:31:09 CST 2001


If I understood well, you create a popup window from the main window and set
the main window var newWind with the handler of the popup. And in the popup,
you want to use this handler to set a popup declared var called theUser.
So it's normal it doesn't work because vars only exists under their window.
You can get your newWind var from the popup with a syntax such
window.opener.newWind....
or better
document.....
because theUser is declared in the popup so it can access directly the form.
another solution is to give the popup a name as you create it 
(ie newWind = open("myurl","mynewwind"...)
and in the popup re-create it with the same name
newWind = open("","mynewwind");
and, as it already exists, you'll get a handle on the previously created
window.

but if you want in the popup to access the from in the popup, 
use directly document.

for the alert messages while errors occurs, it often happens that
the little icon is set ( in the left bottom corner of IE status bar )
but the window doesn't appear.
In a popup you may not have this status bar, so you don't see there was an
error.

-----Message d'origine-----
De : Terrence Donnelly [mailto:pag000 at mail.connect.more.net]
Envoyé : samedi 15 décembre 2001 19:15
À : javascript at LaTech.edu
Objet : [Javascript] Popup window stumper


Could somebody tell me why the following code doesn't work.  This file
is included as a .js file in the head of the main document. A simple
click on a link calls function gologit.  This function correctly
makes a new window and displays the form and image in it, but clicking
on the "Log In" button does nothing at all.  I'm assuming I have
some sort of reference problem and/or confusion between the
parent and child windows, but I am stumped!

Thanks in advance.  

****************************************************************************
***

// golofile.js - opens a login window
//  adapted from
//	The Javascript Source!! http://javascript.internet.com
var newWind
function gologit() {
	if (!newWind || newWind.closed) {
    		newWind = window.open("", "", "HEIGHT=300, WIDTH=250")
		if (!newWind.opener) {
			newWind.opener = window
		}
		var newContent = "<HTML><HEAD><TITLE>Grolier Online
Log-In</TITLE>"

		newContent += "<SCRIPT LANGUAGE='JavaScript'>"
		newContent += "function TryItOut() {"
		newContent += "var theUser =
newWind.document.logform.userbox.value;"
		newContent += "theUser = theUser.toLowerCase;"
		newContent += "var thePassword =
newWind.document.logform.passbox.value;"
		newContent += "var theUserLength = theUser.length-1;"
		newContent += "var theUserFront = theUser.charAt(0);"
		newContent += "var theUserBack =
theUser.charAt(theUserLength);"
		newContent += "var theFile = theUserFront + thePassword +
theUserBack+
'.htm';"
		newContent += "alert(theFile);"
		newContent += "OpenIt(theFile);"
		newContent += "window.close(newWind.opener)"
		newContent += "}"

		newContent += "function OpenIt(theFile) {"
		newContent += "var root;"
		newContent += "if (opener.closed) {"
		newContent += "root = window.open('','');"
		newContent += "root.location.href = theFile;"
		newContent += "} else {"
		newContent += "opener.location.href = theFile"
		newContent += "}"
		newContent += "}"


		newContent += "</SCRIPT></HEAD>"

		newContent += "<BODY><CENTER><IMG
SRC='grolog3.gif'><P>Please enter your
Username and Password<P>"
		newContent += "<FORM NAME='logform'>"
		newContent += "Login Name:&nbsp;<INPUT TYPE='text'
NAME='userbox' VALUE=''
SIZE=10><br>"
		newContent += "Password:&nbsp;&nbsp;&nbsp;&nbsp;<INPUT
TYPE='password'
NAME='passbox' VALUE='' SIZE=10><P>"
		newContent += "<INPUT TYPE='button' NAME='button' VALUE='Log
In'
ONCLICK='newWind.document.TryItOut()'></FORM>"

		newContent += "</CENTER></BODY></HTML>"
		newWind.document.write(newContent)
		newWind.document.close()
	} else {
		newWind.focus()
	}
}

****************************************************************************
*******


-- Terry Donnelly

_______________________________________________
Javascript mailing list
Javascript at LaTech.edu
https://lists.LaTech.edu/mailman/listinfo/javascript
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20011217/bc0fdb6d/attachment.htm>


More information about the Javascript mailing list