zoukankan      html  css  js  c++  java
  • window.open模拟表单POST提交

    
    解决地址栏长度限制,隐藏参数,不在地址栏显示
    项目 excel 导出中用到
    将form的target设置成和open的name参数一样的值,通过浏览器自动识别实现了将内容post到新窗口中
    
    var url=“XXX”;
    var tempForm = document.createElement("form");           
    tempForm.id="tempForm";           
    tempForm.method="post";              
    tempForm.action=url;       
    tempForm.target="blank";           
    //可以定义多个input 传多个参数
    var hideInput = document.createElement("input");           hideInput.type="hidden";           
    hideInput.name="ids";  
    hideInput.value= ids;         
    tempForm.appendChild(hideInput);
    if (tempForm.attachEvent) {  // IE 
    tempForm.attachEvent("onsubmit",function(){ window.open('about:blank','blank'); });  
    } else if (tempForm.addEventListener) {  }
    // DOM Level 2 standard  
    tempForm.addEventListener("onsubmit",function(){ window.open('about:blank','blank')});  
    }              
    document.body.appendChild(tempForm);   
    if (document.createEvent) { }
    // DOM Level 2 standard  
        evt = document.createEvent("MouseEvents");  
        evt.initMouseEvent("submit", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);  
        tempForm.dispatchEvent(evt);  
    } else if (tempForm.fireEvent) { // IE   tempForm.fireEvent('onsubmit');  
    }  
    //必须手动的触发        
    tempForm.submit();         
    document.body.removeChild(tempForm);
  • 相关阅读:
    JMS基本概念
    SSH项目整合
    SSH框架搭建问题总结
    web项目中classPath指的是哪里?
    web项目中配置文件的加载顺序
    分布式电商系统项目总结
    关于javaweb中图片的存储问题
    商品详情页面的显示
    利用solr实现商品的搜索功能
    SSM框架的搭建与测试
  • 原文地址:https://www.cnblogs.com/fengziblog/p/10607907.html
Copyright © 2011-2022 走看看