Open Bug 460885 Opened 16 years ago Updated 2 years ago

Calls to differing JavaScript functions that submit a form to an "external" target only submits form for first function called and other submits seem to be ignored

Categories

(Core :: DOM: Core & HTML, defect, P5)

1.9.2 Branch
x86
Windows XP
defect

Tracking

()

People

(Reporter: matthewadirks, Unassigned)

References

()

Details

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3

Details of problem copied and slightly modified from my post to another forum (source: http://forums.somethingawful.com/showthread.php?threadid=2983507&pagenumber=1&perpage=40#post350968736 ) :

I have some JavaScript functions being dynamically generated by PHP which populates the values of a "hidden" form (form consisting solely of hidden values) on one page and submits this form data to a separate page. This form's target is set to "_blank" so that it posts into a new window/tab and leaves the originating tab/window untouched by the process. Once this second page loads it's post data will be automatically posted yet again to a 3rd page. The first 2 pages are on the same server, the 3rd is on an external site. The generated scripts are called by placing them in the "onload" parameter of the page's body tag as PHP generates the page.

The problem that I face is that I have need to submit the first form multiple times with different values and while my code works as expected in IE7 and Chrome, it falls short in Firefox (only does one submit and stops).

Relevant code and markup follow (note some variable names changed for generalization purposes):

JS Function that sets all forms and anchor links to external targets if they have the "external" class defined, also PHP code inserts dynamically created JS functions:

code:
function externalLinks() { if (document.getElementsByTagName) { var anchors = document.getElementsByTagName("a"); for (var i=0; i < anchors.length; i++) { var anchor = anchors[i]; if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") { anchor.target = "_blank"; } } var forms = document.getElementsByTagName("form"); for (var i=0; i < forms.length; i++) { var form = forms[i]; if (form.getAttribute("action") && form.className == "external") { form.target = "_blank"; } } } } <?php foreach ($ADDITIONAL_JSCRIPTS as $script){ echo ($script . "\n") ; } ?>


Body tag where generated JS functions will be called:
code:
<body onload="externalLinks();<?php echo ($BODY_ONLOAD_STRING); ?>">

Form that is to be posted multiple times to multiple new windows:
code:
<form id="ExportForm" action="export.php" method="post" class="external"> <div id="ExportHiddenFields" class="hiddenFields"> <input type="hidden" name="foo" id="foo" value="" /> <input type="hidden" name="bar" id="bar" value="" /> </div> </form>


PHP code that generates the necessary JS functions and, indirectly, calls them:
(additional note: the setupValidation function just checks that a given field in the main, "non-hidden" form is filled in before it is submitted, it does not effect the hidden form)
code:
$do_export = (is_array($export_array) && !(empty($export_array))); $ADDITIONAL_JSCRIPTS = array(); if ($do_export) { foreach ($export_array as $row_key => $row_array) { $ADDITIONAL_JSCRIPTS[] = (' function InfoSubmit' . $row_key . '(){ var frm; frm = document.getElementById("ExportForm"); frm.foo.value = "'.preg_replace('/"/', '"', $row_array['foo']).'"; frm.bar.value = "'.preg_replace('/"/', '"', $row_array['bar']).'"; frm.submit(); return true; } '); } } $BODY_ONLOAD_STRING .= 'setupValidation();'; if ($ops_export) { foreach ($export_array as $row_key => $row_array) { $BODY_ONLOAD_STRING .= 'InfoSubmit' . $row_key . '();'; } }


As I mentioned before, this works properly in IE7 and Chrome (multiple new tabs/windows open), so I know the code is being generated properly. It's just, for some reason , Firefox will not go past the first function that calls submit(). Is there something in my script I need to tweak so that the JavaScript interpretor will open multiple new windows/tabs in Firefox as it does in IE7 and Chrome ... or is this an actual bug in the JS interpreter?

Reproducible: Always

Steps to Reproduce:
1.Have/put necessary code in place to submit differing posts to multiple new tabs/widows.
2.Run test code.
3.If prompted, allow submissions (if non-secure submission)
Actual Results:  
Only one new tab will open and submit it's form values.

Expected Results:  
Multiple tabs should open. One for each form submitted to a new page and each submitting the values it set to the form's specified action page.

Firefox's JavaScript Interpreter needs to better allow for this kind of multiple submit call. I set the severity as "Major" because submit() is a pretty key function and while this particular style of submission probably isn't used often, it's worrisome enough to wonder how else calls to submit aren't going to operate as one would expect (especially when it works in other browsers that aren't IE and in IE (as messed up as IE's implementation may be)).
This bug persists in 3.0.4.
Summary: Calls to differing JavaScript functions that submit and "external" form only submits form for first function called and other submits seem to be ignored → Calls to differing JavaScript functions that submit a form to an "external" target only submits form for first function called and other submits seem to be ignored
This bug persists in 3.0.5 and 3.0.6.
This bug persists in 3.0.10.
This bug persists in 3.5.2
Flags: blocking-firefox3.6?
Priority: -- → P2
--> Core::JavaScript Engine
Assignee: nobody → general
Component: General → JavaScript Engine
Flags: blocking-firefox3.6?
Product: Firefox → Core
QA Contact: general → general
Version: unspecified → 1.9.2 Branch
jst, this might actually be more with forms; can you look, too?
Flags: blocking1.9.2?
This is probably not JS engine. I don't think this should block, but I'll leave it up to jst.
Assignee: general → nobody
Component: JavaScript Engine → DOM
QA Contact: general → general
Status: UNCONFIRMED → NEW
Ever confirmed: true
Flags: blocking1.9.2? → blocking1.9.2-
This bug persists in 3.6.3 ... in case you were wondering ;-)
Bug is still present in (the otherwise spectacular) Firefox 4.0.
Bug is still present as of Firefox 9.0.1.
Just tested again in Firefox 14.0.1 ... still there. 

Interesting side-note is that it also seems to be a problem in Google Chrome now as well (version 20.0.1132.57).
https://bugzilla.mozilla.org/show_bug.cgi?id=1472046

Move all DOM bugs that haven't been updated in more than 3 years and has no one currently assigned to P5.

If you have questions, please contact :mdaly.
Priority: P2 → P5
Component: DOM → DOM: Core & HTML

It's been several years since I've had anything to report on this but some changes I've made to the code that initially triggered the need to file this report have brought new details to light.

With Microsoft planning to end support for Internet Explorer in 2020 and that being the only browser in which my JavaScript code that made multiple calls to submit a form into new windows actually worked (this bug seems to have spread to other browsers' JavaScript engines as well), I had to think up another way to achieve the same results and looked into posting to an iframe within the same page as the form. I had the code that dynamically set the form values also dynamically create an iframe and set the target of the form to that dynamically generated iframe ... AND IT WORKED. Multiple iframes were created as expected and, into each dynamically created iframe, the information that had been dynamically set on the form was posted accordingly much as the calls to "_blank" had before this bug came to light.

Since multiple submits to the uniquely named iframes work yet multiple submissions to "_blank" do not, it leads me to suspect that there is some sort of check being done on the value of the form's target parameter such that, when submitted, it will not allow multiple submissions to the same target value to take place. Or, perhaps, multiple submissions are not allowed until the submission is completed for a given target by having the page fully loaded which is something that would not likely have happened yet before the next call to the "_blank" target was made even though the next target was, in fact, an entirely new, and thus separate, window (or tab).

Hi Matthew,
You've done a great deal of research on this through all this years, could you please check this out once again in the latest Firefox version or let us know if this is still relevant to keep open?

Flags: needinfo?(matthewadirks)
Severity: major → S3

So, I tweaked my code in a test environment to revert to the old behavior of posting the form to a target of _blank instead of targeting the dynamically created iframes I'd been using. Firefox (now on version 100.0) still only pops up one new tab/window for the initial call to submit() on the specified form and fails to pop up any additional tabs/windows past that despite calls to submit() in proceeding JavaScript functions being executed against that same form. Internet Explorer (which will be retired on June 15 yet partially live on in Microsoft Edge as a compatibility mode) still opens up a new tab/window for each distinct call to submit().

Flags: needinfo?(matthewadirks)
You need to log in before you can comment on or make changes to this bug.