homepage Welcome to WebmasterWorld Guest from 174.129.74.186
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Targetting a window
opened by javascript from a form
joshie76




msg:1483845
 3:19 pm on Sep 27, 2002 (gmt 0)

Take the following (simplified) example:

<form name="testform" method="post" action="test.asp">
<input type="hidden" name="field" value="whatever">
<input type="button" value="go post" onclick="goPost2()">
</form>

<script type="text/javascript">
function goPost()
{
myWin = window.open("page.htm","myWin","width=300")
document.testform.target = "myWin";
document.testform.submit();
}
</script>

The code is opening a (javascript) window and then setting the target of the form to that new window. Great and it works on 48 out of the 50 machines here BUT, infuriatingly, it refuses to work on two IE machines.

The form submit targets a new (like a _blank) window. I've tried everything including adding a delay (up to 8 seconds!) after the open. I've written the code a thousand different ways (without 'myWin =' etc, using a normal submit button and target attribute). I've installed IE5.0 SP2 without luck, upgraded to IE5.5 SP2 and it still didn't work. IE6 nada. The script engine is 5.6 (latest version) and yet it still refuses to target the window opened by script.

The window knows that it's name is myWin as I've used:
document.write(window.self.name) in page.htm.

Please help me before I pull it all my hair, give myself concussion and damage the wall.

Yours desparingly

 

NameNick




msg:1483846
 4:11 pm on Sep 27, 2002 (gmt 0)

joshie76,

I am using the following code and it works always fine:

<form action="file.php" method="post" target="mywin" onSubmit="window.open('', 'mywin', 'width=450,height=300,status=yes,resizable=yes,scrollbars=yes')">

NN

joshie76




msg:1483847
 4:23 pm on Sep 27, 2002 (gmt 0)

Thanks NameNick

The bad news is that your code isn't working on the two machines in question - it opens your javascript window and then opens an entirely new window with the action of your formpost.

This is worrying as I can't find mention of this problem anywhere - one of the problems is that window.open must be one of the most covered javascript topics out there... sinking without trace here.

I really can't explain this and just assumed it an IE bug, but we've upgraded the browser three times and it's still there (they're W2K boxes).

NameNick




msg:1483848
 4:30 pm on Sep 27, 2002 (gmt 0)

... it opens your javascript window and then opens an entirely new window with the action of your formpost.

It is necessary that you write the windows name in each of the targets. In form tag it is e.g.

target="yourwindow"

and in the javascript code it is

onSubmit="window.open('', 'yourwindow', 'width=450,height=300,status=yes,resizable=yes,scrollbars=yes')"

If you put different window names in each code you will get one window opened by html and one window opened by the javascript code.

NN

joshie76




msg:1483849
 7:56 am on Sep 30, 2002 (gmt 0)

Thanks NameNick,

I'm down with the naming thing though. In the example I posted above I set the target using javascript:

document.testform.target = "myWin";

And I've tried it with the attribute on the <form> tag itself but it still isn't working no these two machines. I even cut and pasted your code and tried it - it didn't work.

This is baffling everyone I've had look at it. When it happened on one machine at first we kind of just put it down to a 'freak' event on a rogue machine... until we got another call.

Our concern is that going from the stats here we could be looking at 4% of users (admittedly, 2 out of 50 isn't the strongest basis for such a statistical analysis but thats our concern nonetheless).

Anybody heard of anything like this?

[edited by: joshie76 at 8:05 am (utc) on Sep. 30, 2002]

Sinner_G




msg:1483850
 8:04 am on Sep 30, 2002 (gmt 0)

Are these the 2 only IE machines in your 50? It would (maybe) help to know what's different on those 2 machines compared to the 48 others.

joshie76




msg:1483851
 8:08 am on Sep 30, 2002 (gmt 0)

We're trying to work that out. But at the moment the only difference we can find is that when you post (or GET even) to a javascript popup it opens an entirely new window! ;)

Machines here are built, like most other offices from a standard ghost. I've hunted through the installed programs and plug-ins but there's nothing out of the ordinary...

All machines have IE on them (various versions, one per machine).

Railbird




msg:1483852
 8:30 am on Oct 2, 2002 (gmt 0)

Hey guys,
Oddly enough I wrestled the same prob this eve & wuz reading your post, then found this link... and wah-lah. Worked for me :)

[infinitemonkeys.atrax.co.uk...]

What I don't see you doing, is setting a RETURN in your onSubmit, and in the JS function. As this link points out, the RETURN is what allows the blank window to open, before returning control back to the FORM tag with ACTION= .asp file.

Hope this helps, I grab tips off these Forums alot & it would be cool to give one for a change...
Railbird

joshie76




msg:1483853
 10:51 am on Oct 2, 2002 (gmt 0)

Hi Railbird and welcome to the forums,

Unfortunatley I've tried the return method and just tested your exact code but these two machines still refuse to target the pop-up window.

If you really think about it programmatically then "the RETURN is what allows the blank window to open, before returning control back to the FORM tag with ACTION= .asp file." doesn't hold programmatically (especially if you consider the first example I posted with an added delay before the submit) but I'll try anything once. It's funny fixes like this that often sneak through.... no such luck.

I'm totally exhaused on this one. It would help If I knew the scale of the problem or whether it's just these two machines.

Thanks for trying tho'

:(

jmarzou




msg:1483854
 4:43 pm on Nov 15, 2002 (gmt 0)

Hi all,

I have the same problem that Josie76 encountered.

Here's a sample of my code :

**********************************************************
function JS_SetTarget(sTarget)
{
document.all["frm"].target = sTarget;
}

function JS_OnSubmit()
{
var sTarget = document.all["frm"].target;

if (sTarget == "MyPopUp")
{
var sFeatures = "resizable=yes,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes";

sFeatures += ",width=" + screen.availWidth * 0.80;
sFeatures += ",height=" + screen.availHeight * 0.80;
sFeatures += ",left=" + screen.availWidth * 0.10;
sFeatures += ",top=" + screen.availHeight * 0.10;

var win = window.open("", "MyPopUp", sFeatures);

setTimeout('document.all["frm"].submit()', 1000);

return false;
}
else
{
return true;
}
}

...

<FORM ID="frm" ACTION="mytargetpage.asp" METHOD="POST" TARGET="MyFrame" onSubmit="return JS_OnSubmit();">
...

<INPUT ID="btnExecute1" TYPE="SUBMIT" VALUE="Execute 1" onClick="JS_SetTarget('MyFrame')">

<INPUT ID="btnExecute2" TYPE="SUBMIT" VALUE="Execute 2" onClick="JS_SetTarget('MyPopUp')">
**********************************************************

The goal is to display the content of mytargetpage.asp in a frame if btnExecute1 is pressed or in
a new window if btnExecute2 is pressed.

The POST method is used, because one of the parameters sent to mytargetpage.asp is a SQL query, which can be
very long and can embedded some problematic chars like '+'...

On some machine, this code works well. On others, a blank window is first opened (named 'MyPopUp') and
then a second one is opened, and the second one has the role of target!

NB: A greater value of timeout has no effect on this problem.

If someone could help...

Thanx in advance.

jmarzou

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved