且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用异步通信将表单数据发送到test.html?

更新时间:2023-11-27 15:00:28

If the document originates from same origin as original document and is opened by user action you can pass the parameters as a query string.

  document.querySelector("input[type=button]").onclick = e => {
    // pass key, value pairs to `test.html`
    const test = window.open(`test.html?${key}=${value}`, "_blank");
  }

at opened window get and parse location.search

  onload = () => {
    // do stuff with key, value pairs passed from `window.opener`
    console.log([...new URLSearchParams(location.search).entries()])
  }

plnkr http://plnkr.co/edit/MlCQZpkfBXFwxdR6gz5x?p=preview