提交输入类型的window.open createElement'form'未调用操作

问题描述

我正在尝试使用javascript中的自定义表单打开一个新窗口

在表单中,我具有一些字段和动作以及Submit输入(请注意,该元素应为input type = submit

但是,在弹出窗口中单击“提交”按钮时,不会执行提交操作。

    var map = window.open("","editormap",'width=600,height=600,scrollbars=no,resizable=no');
    
        var mapForm = map.document.createElement('form');
        mapForm.target = "editormap";
        mapForm.id="inpForm";
        mapForm.method = "POST"; 
        mapForm.action = "/dashboard/save/"+val1+"/"+val2;
    
      var mapInput3 = map.document.createElement('input');
      mapInput3.type = 'submit';
      mapInput3.name = 'submit';
      mapInput3.value = 'Submit';
      mapForm.appendChild(mapInput3);
    
       var  mapInput = map.document.createElement('input');
        mapInput.type = "button";
        mapInput.name = "cancel";
        mapInput.value = "Cancel";
        mapInput.onclick=map.close;
        mapForm.appendChild(mapInput);
        
    
      var  mapInput1 = map.document.createElement("textarea");
        mapInput1.name = "code";
        mapInput1.value = repoValues;
        mapForm.appendChild(mapInput1);
        
     var mapInput2 = map.document.createElement("input");
     mapInput2.type = "hidden";
    mapInput2.name = "filename";
    mapInput2.value = 'some data';
    mapForm.appendChild(mapInput2);
    
   map.document.body.appendChild(mapForm); 

我还尝试过如下所示的绑定

var parentForm = document.createElement.bind(document);
var mapForm = parentForm('form');

仍然提交者未执行请求的操作。

请帮助或指导正确的方向。

解决方法

由于窗口的位置为空,因此相对URL没有相对于其的基本URL。因此,您需要在action URL中提供完整的URL。

        mapForm.action = "https://www.example.com/dashboard/save/"+val1+"/"+val2;

DEMO

(堆栈片段不允许弹出窗口,因此我必须使用jsfiddle进行演示。)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...