IE 11 формирует сообщение в новом окне не работает, когда файл размещен на http-сервере - PullRequest
0 голосов
/ 25 апреля 2018

У меня есть форма в моем html

<form id="lippForm" name="form1" action="https://somesite/entry" target="Frame" > и в файле js я открываю новое окно, когда кнопка отправки формы нажимается с

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'); Затем я устанавливаюцель этой формы в новом окне,

document.getElementsByName("form1")[0].target = "Frame"; Для браузеров, отличных от IE11, это работает, и ответ сообщения формы отображается в новом окне.Но в IE11 это работает только тогда, когда я открываю HTML прямо в браузере.Если я предоставлю html и js-файл на локальном хосте, ответ на пост формы будет отображаться в родительском окне, а новое открытое окно будет пустым.Я думаю, что это как-то связано с проверкой домена в IE11, поскольку это происходит только тогда, когда я размещаю его на сервере?Кто-нибудь знает почему и есть ли вообще обойти это?Спасибо

1 Ответ

0 голосов
/ 25 апреля 2018

Единственный способ, который я нашел, чтобы решить вашу проблему - это клонировать весь элемент формы, скрыть его, чтобы он не отображался, добавить его в новое окно и затем отправить его.

Я использовал этот код JavaScript и работал нормально во всех браузерах:

/**
 * 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);
}

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>

Я тестировал его в Internet Explorer 11, Edge, Chrome (Mac / PC), Firefox (Mac / PC) и Safari.

Надеюсь, это поможет!

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...