Last Comment Bug 460885 - 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
: Calls to differing JavaScript functions that submit a form to an "external" t...
Status: NEW
:
Product: Core
Classification: Components
Component: DOM (show other bugs)
: 1.9.2 Branch
: x86 Windows XP
P5 major with 1 vote (vote)
: ---
Assigned To: Nobody; OK to take it and work on it
:
: Andrew Overholt [:overholt]
Mentors:
N/A
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2008-10-20 17:48 PDT by Matthew Dirks
Modified: 2018-06-28 21:40 PDT (History)
5 users (show)
beltzner: blocking1.9.2-
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments

Description User image Matthew Dirks 2008-10-20 17:48:52 PDT
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)).
Comment 2 User image Matthew Dirks 2008-11-14 09:32:28 PST
This bug persists in 3.0.4.
Comment 3 User image Matthew Dirks 2009-03-02 06:15:43 PST
This bug persists in 3.0.5 and 3.0.6.
Comment 4 User image Matthew Dirks 2009-05-29 10:36:09 PDT
This bug persists in 3.0.10.
Comment 5 User image Matthew Dirks 2009-08-27 17:04:29 PDT
This bug persists in 3.5.2
Comment 6 User image Mike Beltzner [:beltzner, not reading bugmail] 2009-09-08 14:46:37 PDT
--> Core::JavaScript Engine
Comment 7 User image Mike Beltzner [:beltzner, not reading bugmail] 2009-09-08 14:47:20 PDT
jst, this might actually be more with forms; can you look, too?
Comment 8 User image Blake Kaplan (:mrbkap) 2009-09-17 11:22:55 PDT
This is probably not JS engine. I don't think this should block, but I'll leave it up to jst.
Comment 9 User image Matthew Dirks 2010-04-08 11:12:52 PDT
This bug persists in 3.6.3 ... in case you were wondering ;-)
Comment 10 User image Matthew Dirks 2011-04-25 07:00:14 PDT
Bug is still present in (the otherwise spectacular) Firefox 4.0.
Comment 11 User image Matthew Dirks 2012-01-11 14:04:19 PST
Bug is still present as of Firefox 9.0.1.
Comment 12 User image Kyle Huey [:khuey] (Exited; not receiving bugmail, email if necessary) 2012-01-11 14:07:41 PST
Mounir, can you look at this?
Comment 13 User image Matthew Dirks 2012-07-18 08:58:31 PDT
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).
Comment 14 User image Firefox Product Integrity Bug Husbandry Bot (contact :emceeaich) 2018-06-28 21:40:09 PDT
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.

Note You need to log in before you can comment on or make changes to this bug.