0

I have a form in my html

<form id="lippForm" name="form1" action="https://somesite/entry" target="Frame" > and in the js file, I open a new window when the form submit button is clicked with

win = window.open('about:blank', 'Frame', 'top=' + top + ', left=' + left + ', width=' + width + ', height=' + height + ', location=no, status=1, toolbar=0, menubar=0, resizable=1, scrollbars=1'); Then I set the target of this form into the new window,

document.getElementsByName("form1")[0].target = "Frame"; For browsers other than IE11, this works and the response of the form post shows in the new window. But on IE11, this works only when I open the html directly with the browser. If I serve the html and the js file on a localhost, the form post response will show in the parent window and the newly opened window will be blank. I think it has something to do with the domain check in IE11 since it only happens when I hosts it on the server? Does anyone know why and is there anyway to bypass this? Thanks

S.W
  • 21
  • 7
  • Just put `target="_blank"` in the `
    ` element instead of using scripts.
    – Dai Apr 24 '18 at 22:26
  • I believe what you meant is target = "frame" but I tried and it did not work let me update my thread. – S.W Apr 24 '18 at 22:34
  • No, I really meant `target="_blank"`. `_blank` is a special reserved value which means "a new window". See here: https://stackoverflow.com/questions/896724/how-to-open-a-new-window-on-form-submit – Dai Apr 24 '18 at 22:36
  • thanks for the reply. I tried _blank but the result is the same. The post response is still in the parent window not in the new window. – S.W Apr 24 '18 at 22:41

2 Answers2

0

The only way around that i found to solve your problem is to clone the entire form element, hide it so it won't be displayed, inject it in the new window and then submit it.

I used this javascript code and worked fine on all browsers:

/**
 * Sending form in a new window function
 */

function submitInNewWindow(event) {

    // Prevents default so the form won't be submitted
    event.preventDefault();

    // SOme variables
    var win, container;

    // Opens the new window
    win = window.open('about:blank', 'Frame', 'top=0, left=0, width=250, height=250, location=no, status=1, toolbar=0, menubar=0, resizable=1, scrollbars=1');

    // Creates a container to hold the cloned form
    container = win.document.createElement('div');

    // Gets the form HTML and uses it as the container HTML
    container.innerHTML = document.getElementById('form').outerHTML;

    // Hides the container
    container.style.display = 'none';

    // Injects the container in to the new window
    win.document.body.appendChild(container);

    // Submits the new window form
    win.document.querySelector('form').submit();

}

// Gets the form element
var form = document.getElementById('form');

// Attachs the event (for modern browsers)
if(typeof form.addEventListener === 'function') {
    window.addEventListener('submit', submitInNewWindow, false);
}

// Attaches the event for old Internet Explorer versions
else {
    form.attachEvent('onsubmit', submitInNewWindow);
}

The HTML:

<form action="http://localhost/test/" id="form" name="form" method="post" target="Frame">
    <input id="field1" name="field1" type="hidden" value="1234" />
    <input id="field2" name="field2" type="text" value="5678" />
    <input type="submit" value="send">
</form>

I've tested it on Internet Explorer 11, Edge, Chrome (Mac/PC), Firefox (Mac/PC) and Safari.

Hope it helps!

muecas
  • 4,265
  • 1
  • 8
  • 18
0

Did you try update policy configration?

Open Local Security Policy Under Local Policies / Security Options branch, Enable "User Account Control: Use Admin Approval Mode for the built-in Administrator account".

Nolan Shang
  • 2,312
  • 1
  • 14
  • 10