问题描述
我有2个窗口 home.html
和 result.html
。
在 home.html
我有< textarea>
#txtinput 和< button>
#btn 。
In result.html
我还有另一个< textarea>
#txtresult 。
In result.html
I have another <textarea>
#txtresult.
在 home.html
上,如果我在 #txtinput 中输入一个值并点击 #btn ,我想打开 result.html
并将 #txtinput 的值传递给 #txtresult 。
On home.html
, if I enter a value into #txtinput and click #btn, I want to open result.html
and pass the value of #txtinput into #txtresult.
我在另一篇帖子中尝试了以下代码,该帖子在新窗口的正文中显示了值,但不会在我的元素中显示
I've tried the below code from another post, which displays the value in the new window's body but won't display it in my element
var myWindow = window.open();
myWindow.document.body.innerHTML = document.getElementById("txtinput").value;
以某种方式以某种方式可行吗?我对JavaScript比较陌生,我的课程现在正在进行中,我很想知道如何做到这一点。任何详细的帮助将非常感谢!
Is it somehow possible in a simple way? I am relatively new to JavaScript, my courses are ongoing now and I am just curious to know the ways to do it. Any detailed help will be very much appreciated!
推荐答案
我希望我需要详细说明下面的代码
I hope i need to elaborate the below code
主页上点击功能的按钮:
Button on click function in the home page:
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");
}
检索结果页面中的值:
$(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);
});
有关sessionStorage的详细信息
For more information about sessionStorage
- code.google.com/p/sessionstorage/
- developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Storage
我做了与上面相同的事情,在新窗口中获取值很好,但是我只在documet.ready()函数中得到的值。所以我无法在JSP中使用这些值。一旦我得到了值,我需要在JSP中显示它们。
I have done same thing as above, am getting values in new window that's great, but that values I am getting only in documet.ready() function. So I am not able to use these values in my JSP. once I got values I need to display them in JSP.
这篇关于如何使用javascript将值从父窗口传递到另一个html页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!