一路繁花似锦绣前程
失败的越多,成功才越有价值

导航

 
openWindowWithPost(url) {
  const name = 'NEWWIN' + Date.now();
  const params = Object.fromEntries(new URL(url).searchParams);
  // 打开新窗口(可为空或目标地址)
  const newWindow = window.open(url, name, 'width=800,height=600');
  if (!newWindow) return null;
  // 创建表单
  const form = document.createElement('form');
  form.method = 'POST';
  form.action = url;
  form.target = name;
  // 添加参数
  for (const key in params) {
    if (params.hasOwnProperty(key)) {
      const input = document.createElement('input');
      input.type = 'hidden';
      input.name = key;
      input.value = params[key];
      form.appendChild(input);
    }
  }
  // 插入表单并提交
  document.body.appendChild(form);
  form.submit();
  document.body.removeChild(form);
  return newWindow;
}
posted on 2026-05-06 18:03  一路繁花似锦绣前程  阅读(4)  评论(0)    收藏  举报