Link to home
Start Free TrialLog in
Avatar of Glauron
Glauron

asked on

Submit form to new window or parent window - compatable with FF & IE?

As per the title ...
My situation is, user of site clicks on "Login" from any of the main public pages, which opens a small popup to grab the User Id & Password, when they submit I (read the Boss) wants it to either:
a) Open a NEW window which logs in & displays user's control page.
b) Login & display control panel on the ORIGINAL page, where the usr clicked "Login"
In both cases, the little popup login window is to close.

I thought this would be simple - probably just overlooked something.

With a)
IE works fine. Firefox opens the new window as a TAB inside the teensy weensy login popup :|
Tried creating new window and used both window handle and window name as the target with no luck, still in a tab, and IE opens a blank window PLUS a windowto which it submits the form.

With b)
Neither browser seems to recognize the parent as a target for the form.
Tried "target" = _blank, _new, _parent, _top
Tried javascript "onsubmit" passing the form ('this') as argument to a function, into a variable 'f'.
With that, I've tried f.target=window.opener; f.target=window.opener.name;

What am I missing?

My basic logic "attached as code snippet" so not sure where it appears, but it's here somewhere.

Thanks a bundle :)

<html>
	<head>
		<script language="javascript" type="text/javascript">
 
			function checkForm ( f )
			{
				if ( checkLogin() )
				{
					f.target = window.opener.name;
					//f.target = window.opener;
					//f.target = parent;
					f.submit();
					self.close();
				}
				else
				{
					return false;
				}
			}
	        </script>
	</head>
	<body>
		<form action="%server_url%/cgi-bin/_front/services.cgi" method="POST" name="loginForm"
			id="loginFormID" onsubmit="return checkForm( this )" target="_new">
			<!-- tried above: target="_new" target="_blank" target="_parent" target="_top" etc. -->
 
			<input type="hidden" name="action" value="login" />
 
			UID: <input type="text" name="uid" /> <br />
			PASS: <input type="text" name="pin" /> <br />
			<input type="submit" name="submit" value="LOGIN" />
 
		</form>
	</body>
</html>

Open in new window

Avatar of Glauron
Glauron

ASKER

"Tried creating new window and used both window handle and window name as the target with no luck."

I'll expand on that...
Note, the timeouts were an attempt to stop IE from opening a blank window, AND a second window with the page I wanted.
			function checkForm ( f )
			{
				if ( checkLogin() )
				{
					var myWin = window.open('', 'controlPage');
					setTimeout("f.target = 'controlPage';", 250);
					setTimeout("f.submit();", 350);
					setTimeout("self.close()", 500);
					//f.submit();
					//self.close();
				}
				else
				{
					return false;
				}
			}

Open in new window

Avatar of Michel Plungjan
you should never submit in the submit event

function checkForm ( f ) {
  if ( checkLogin() ) {
    f.target = window.opener.name;
    setTimeout('window.close()',200);
    return true; // allow the submit
  }
  return false;
}
or

function checkForm ( f ) {
  if ( checkLogin() ) {
    var myWin = window.open('', 'controlPage');
    f.target = 'controlPage'; //  if the above  fails, the target will still open a new window
    setTimeout("self.close()", 500);
    return true; // allow submit
  }
  return false;
}
I am assuming your checkLogin does nothing strange and works and exists
Avatar of Glauron

ASKER

Yes checkLogin exists, and does nothing more than check form values & show "alerts" / "confirms" if it finds something wrong. Returns true/false (false if problems in form).

I've actually figured out what I was doing wrong, and it was a simple little thing like I had imagined ...
I got it working with existing code just by running
window.name = 'windowABC123';
in some JS on the opening window, so the child window actually had a name to reference. I guess I though the browsers would supply a default window name or some such. :/

Thanks for the tip re: invoking the submit event. Knowing best practices is always a plus.
Riiight... I saw the window.opener.name and of course assumed you had coded that already :))
ASKER CERTIFIED SOLUTION
Avatar of Computer101
Computer101
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial