如何使用javascript将值从父窗口传递到另一个html页面?

loc*_*ies 10 javascript window.open

我有2个窗户home.htmlresult.html.

home.html我有一个<textarea> #txtinput<button> #btn.

result.html我有另一个<textarea> #txtresult.

home.html,如果我输入一个值#txtinput并单击#btn,我想开result.html并传递价值#txtinput#txtresult.

我从另一篇文章中尝试了下面的代码,它在新窗口的主体中显示了值,但是不会在我的元素中显示它

var myWindow = window.open();
myWindow.document.body.innerHTML = document.getElementById("txtinput").value;
Run Code Online (Sandbox Code Playgroud)

它是以某种方式以简单的方式实现的吗?我对JavaScript比较陌生,我的课程现在正在进行中,我很想知道如何做到这一点.任何详细的帮助将非常感谢!

小智 16

我希望我需要详细说明以下代码

主页上的单击功能按钮:

function sample(){
    //this will set the text box id to var id;
    var id = document.getElementById("text_box_id").id;

    //the sessionStorage.setItem(); is the predefined function in javascript
    //which will support for every browser that will store the sessions.
    sessionStorage.setItem("sent", id); 

    //this is to open a window in new tab
    window.open("result.html","_blank");
}
Run Code Online (Sandbox Code Playgroud)

检索结果页面中的值:

$(document).ready(function(){
    //This sessionStorage.getItem(); is also a predefined function in javascript
    //will retrieve session and get the value;
    var a = sessionStorage.getItem("sent");
    alert(a);
});     
Run Code Online (Sandbox Code Playgroud)

有关sessionStorage的更多信息

我已经完成了与上面相同的事情,我在新窗口中获取的值很好,但是我只在documet.ready()函数中获得了这些值.所以我无法在JSP中使用这些值.一旦我得到了值,我需要在JSP中显示它们.