zoukankan      html  css  js  c++  java
  • window.open以post方式提交(转)

    function openWindowWithPost(url,name,keys,values)    
    {    
        var newWindow = window.open(url, name);    
        if (!newWindow)    
            return false;    
                
        var html = "";    
        html += "<html><head></head><body><form id='formid' method='post' action='" + url + "'>";    
        if (keys && values)    
        {    
           html += "<input type='hidden' name='" + keys + "' value='" + values + "'/>";    
        }    
            
        html += "</form><script type='text/javascript'>document.getElementById('formid').submit();";    
        html += "</script></body></html>".toString().replace(/^.+?*|\(?=/)|*.+?$/gi, "");     
        newWindow.document.write(html);    
            
        return newWindow;    
    }  
    function openPostWindow(url, data, name)       
        
      {       
        
         var tempForm = document.createElement("form");       
        
         tempForm.id="tempForm1";       
        
         tempForm.method="post";       
           
         //url  
         tempForm.action=url;       
         //open方法不能设置请求方式,一般网页的post都是通过form来实现的。  
         //如果仅仅模拟form的提交方式,那么open方法里那种可设置窗体属性的参数又不能用。  
         //最后想办法整了这么一个两者结合的方式,将form的target设置成和open的name参数一样的值,通过浏览器自动识别实现了将内容post到新窗口中  
         tempForm.target=name;       
        
           
        
         var hideInput = document.createElement("input");       
        
         hideInput.type="hidden";       
        
         //传入参数名,相当于get请求中的content=  
         hideInput.name= "content";  
        
         //传入传入数据,只传递了一个参数内容,实际可传递多个。  
         hideInput.value= data;     
        
         tempForm.appendChild(hideInput);        
        
         tempForm.attachEvent("onsubmit",function(){ openWindow(name); });     
        
         document.body.appendChild(tempForm);       
        
        
        
         tempForm.fireEvent("onsubmit");     
        
         //必须手动的触发,否则只能看到页面刷新而没有打开新窗口  
         tempForm.submit();     
        
         document.body.removeChild(tempForm);     
        
    }     
        
        
        
    function openWindow(name)       
        
    {       
        
         window.open('about:blank',name,'height=400, width=400, top=0, left=0, toolbar=yes, menubar=yes, scrollbars=yes, resizable=yes,location=yes, status=yes');        
        
    }       
  • 相关阅读:
    UNIX网络编程——Socket通信原理和实践
    UNIX环境高级编程——单实例的守护进程
    UNIX环境高级编程——初始化一个守护进程
    UNIX环境高级编程——创建孤儿进程
    UNIX环境高级编程——实现uid to name
    CentOS7中使用yum安装Nginx的方法
    centos7配置IP地址
    关于Dubbo的原理以及详细配置
    关于Java大数操作(BigInteger、BigDecimal)
    关于JSON 与 对象 、集合之间的转换
  • 原文地址:https://www.cnblogs.com/yellowcool/p/8267226.html
Copyright © 2011-2022 走看看