RhodryCZ
RhodryCZ

Reputation: 139

Creating form in javascript works in Chrome, not in Edge?

I have interesting case of what the hell is going on that I cannot seem to solve.

I need to programatically create a form and send it as post request. My request then returns some html layout and draws it to window that posted the request. This is why I create new window at the bottom. Solution I have is as follows

// Define params
var path = someRequestPath;
var params = {
    DOCNAME: 'DocumentName',
    FORMAT: 'A4',
    ORIENTATION: 'Landscape',
    HTML: htmlContent
};

// Create form to submit request
var form = document.createElement('form');
form.method = "POST";
form.action = path;

// Set form params
for (var key in params) {
    if (params.hasOwnProperty(key)) {
        var hiddenField = document.createElement('input');
        //hiddenField.type = 'hidden';
        hiddenField.name = key;
        hiddenField.value = params[key];

        form.appendChild(hiddenField);
    }
}

//Create window and submit form
var win = window.open('', 'windowName', 'width=1400,height=1200');
win.document.body.appendChild(form);
form.submit();
win.focus();

Now this solution work perfectly fine in Chrome, but in Edge I get following error Object doesn't support property or method "Symbol.iterator". It happens on line where I attach the form to the newly opened window via appendChild. Since Edge is running Chromium core, I expected that it would behave the same, but obviously it does not.

Any ideas?

Thanks.

Upvotes: 0

Views: 747

Answers (2)

Deepak-MSFT
Deepak-MSFT

Reputation: 11355

From your below description,

enter image description here

It looks like you are assuming that you are using the Edge Chromium browser but as per my test results, it looks like you are using the Edge legacy browser.

I try to test your sample code in both the Edge Chromium browser and the Edge legacy browser.

Your code works fine in the Edge Chromium browser and giving the same result as the Google Chrome browser.

Test result with the Edge Chromium Version 87.0.664.55:

enter image description here

Your code giving the Below error on the same line in the Microsoft Edge legacy version 44.19041.423.0:

enter image description here

Michel has already provided the suggestion to fix this issue in his comment.

So I suggest you can try to check and confirm that which Edge browser you are using on your side for making this test. If you want to move to the MS Edge Chromium browser then you can download it from this link.

Let me know if I have misunderstood anything from your description, I will try to correct myself.

Thanks for your understanding.

Upvotes: 1

Leonard Buhl
Leonard Buhl

Reputation: 96

Take a look at this: Edge 15 throws error when using 'for ... of' on a NodeList

It seems to be a problem with Edge not implementing the for ... of/in in NodeList.

Maybe try using for (var key in Array.from(params))

Upvotes: 0

Related Questions