View Full Version : Form2Popup
ShMiL
04-16-2003, 05:32 PM
I need to submit a form so that the action page will open in a new page. I used: <form target="blank"....> but it's good enough...
Is there a way to submit a form to a popup? meaning: onsubmit a popup window will be opened and the action page in it will get the data through the post method.
Is it possible?
Thanks!!
beetle
04-16-2003, 05:46 PM
Yup.
function createTarget( t )
{
window.open( 'about:blank', t, 'width=500, height=400 );
return true;
}
...
<form ... target="someTarget" onsubmit="return createTarget( this.target )" ... >
Or, whatever window options you'd like.
ShMiL
04-16-2003, 06:23 PM
great idea!
Thanks
ShMiL
04-16-2003, 07:17 PM
the form is in a <div> in page A, and let's call the popup: B.
Can I put a script in page B which will change the content of the <div> in page A?
Thanks...
beetle
04-16-2003, 07:23 PM
yes
ShMiL
04-16-2003, 07:34 PM
I know you'll be angry... :( but how can I refer to page A? I don't know it's "name"...
beetle
04-16-2003, 07:42 PM
window.opener will give you a reference to the opening, er, window.
ShMiL
04-16-2003, 08:53 PM
I read about it a little and tried to run this:
window.opener.document.bgColor = "#000000";
from the popup - but I get error that says: "Access denied" - any idea why?
Thanks
beetle
04-16-2003, 09:13 PM
Uh, not right of the bat. I don't mess with opener stuff much. Are the two pages within the same domain?
ShMiL
04-16-2003, 09:26 PM
you're either lucky or damn-experienced :)
two different domains... If I name the pages, will it work?
beetle
04-16-2003, 09:33 PM
Nope. And, experienced would be the answer to your query :D
You cannot perform any cross-domain writing (and some reading) for security and integrity issues. The browser just won't allow it. Since setting the bgColor property is a write operation, you cannot do it.
ShMiL
04-19-2003, 05:32 PM
let's say it's the same domain, but I don't want to use OPENER...
How can I refer to the window (I know it's name...) - I tried this:
window.main .document.bgColor = "#000000";
and it didn't work (main is the name of the window...)
Am I doing it right?
Thanks
beetle
04-20-2003, 06:29 AM
Try just
windowName.document.etc
kwhubby
04-20-2003, 07:05 AM
just a question... would a page have a window name if its not a popup thats window name was difined from one of the parameters in window.open?
ShMiL
04-20-2003, 07:21 AM
Originally posted by kwhubby
just a question... would a page have a window name if its not a popup thats window name was difined from one of the parameters in window.open?
window.name = "main";
ShMiL
04-20-2003, 07:28 AM
Originally posted by beetle
Try just
windowName.document.etc
I get this error:
windowName is undefined
:(
ShMiL
04-20-2003, 07:32 AM
Maybe the process of the popup is the problem...
I pop up a window from page A and I call this popup B.
The address in the popup (B) is from another domain, which redirects to a page in the same domain of A.
From there, I try to change stuff at page A.
Is it ok?
kwhubby
04-20-2003, 09:26 AM
window.name = "main";
oh..... cool... thanks :) ShMil. how simple
Ive never needed to name a window thats not a popup, (id just use opener to access it).
glenngv
04-21-2003, 10:18 AM
Originally posted by ShMiL
Maybe the process of the popup is the problem...
I pop up a window from page A and I call this popup B.
The address in the popup (B) is from another domain, which redirects to a page in the same domain of A.
From there, I try to change stuff at page A.
Is it ok?
once the popup page is in the same domain as the opener, you can access stuff in opener. you have to use the opener property not the window name.
window.opener.document.bgColor="#000000";
ShMiL
04-21-2003, 10:35 PM
Error:
"window.opener is null or not an object"
I can't get this work...
glenngv
04-22-2003, 06:26 AM
is the popup in frames? if yes, use top.opener instead.
ShMiL
04-22-2003, 07:29 AM
no frames...
This is the form in domain A:
<form target="submit2" method="post" name="mazkira" action="Domain B" onSubmit="return checkForm();">
<table>
<tr>
<td width=62>namr</td>
<td width=30></td>
<td><input type="text" class="teva2" name="fullname" maxlength="40" size="20"></td>
</tr>
<tr>
<td>e-mail</td>
<td></td>
<td><input type="text" class="teva2" name="email" dir="ltr" maxlength="80" size="20"></td>
</tr>
<tr>
<td>phone</td>
<td></td>
<td><input type="text" dir="ltr" class="teva2" name="phone_num" maxlength="20" size="20"></td>
</tr>
<tr>
<td>cell</td>
<td></td>
<td><input type="text" dir="ltr" class="teva2" name="cell_num" maxlength="20" size="20"></td>
</tr>
<tr>
<td colspan="3">comments<br><textarea class="teva2" name="comments" cols="40" rows="6" onKeyDown="textCounter(document.mazkira.comments,150);" onKeyUp="textCounter(document.mazkira.comments,150);"></textarea></td>
</tr>
<tr>
<td colspan="3" align="center"><input type="submit" name="submit1" value=" send " class="button"></td>
</tr>
</table>
</form>
the function checkForm (onsubmit) checks validity and then:
popup('about:blank','submit2','yes','yes','yes','470','160');
After submiting, I get a new window with page (.asp - doing some dynamic stuff) from Domain B.
Then, the .asp redirects to a page in Domain A (original) and this is it's source:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="expires" content="0">
<meta HTTP-EQUIV="Content-Type" content="text/html; charset=windows-1255">
<title>הודעתך נתקבלה. תודה.</title>
<meta name="Author" content="Shmulik Simchony">
<meta name="Keywords" content="">
<meta name="DESCRIPTION" content="">
</head>
<!--ff-->
<body style="background-color:#ABC6E5;direction:rtl;" onLoad="javascript:window.opener.bgColor='#000000';">
<table style="margin-left:auto;margin-right:auto;border:0px;width:100%;" cellpadding=0 cellspacing=0>
<tr>
<td style="padding:10px;text-align:center;font-family:Tahoma,Arial;font-size:11pt;" valign="middle">Success!</td>
</tr>
</table>
</body>
</html>
And I get the error I told you. Maybe now it'll be easier to help...
glenngv
04-23-2003, 10:20 AM
it should be:
window.opener.document.bgColor='#000000';
but as you said, window.opener is null.
are sure it is? try alerting it before setting the color.
ShMiL
04-23-2003, 05:50 PM
I don't know if it works yet because I have a background-image in the main page... But I don't get any error which is good...
If I want to refresh the main page, Should I do it like that:
window.opener.refresh()? (I tried it and it didn't work...)
Thanks
glenngv
04-24-2003, 02:40 AM
there is no refresh() method for any object. it should be reload():
window.opener.location.reload()
ShMiL
04-24-2003, 11:21 AM
It's not working - no errors, but still not working.
Is the fact I'm using frames in the main page can cause it??
If it was the problem, I should have probably got the ACCESS DENIED error (the main page is a frameset from a totally different domain...)
Any idea?
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.