window.open 以post方式传递参数示例代码

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

window.open 以post方式传递参数示例代码

  2020-05-13 我要评论
复制代码 代码如下:

//打开新页面并利用post方式传递参数
function openNewPageWithPostData(postAddress,opentype,paramNames,paramValues)
{
var newWindow = window.open(postAddress,opentype);
if (!newWindow)
{
return false;
}

var postDataHtml="<html><head></head><body>";
postDataHtml = postDataHtml + "<form id='postDataForm' method='post' action='"+postAddress+"'>";

if (paramNames && paramValues && (paramNames.length == paramValues.length))
{
for(var i=0 ; i<paramNames.length ; i++)
{
postDataHtml = postDataHtml + "<input type='hidden' name='"+paramNames[i]+"' value='"+paramValues[i]+"'/>";
}
}

postDataHtml = postDataHtml + "</form><script type=\"text/javascript\"> document.getElementById(\"postDataForm\").submit()<script><body><html>";
newWindow.document.write(html);
return newWindow;
}

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们