gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 02:33:41 25 4
gpt4 key购买 nike

我有 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;

是否有可能以一种简单的方式实现?我对 JavaScript 比较陌生,我的类(class)现在正在进行中,我只是想知道如何做。非常感谢任何详细的帮助!

最佳答案

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

首页点击功能的按钮:

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的更多信息

我做了与上面相同的事情,在新窗口中获取了很棒的值,但我只在 documet.ready() 函数中获取了这些值。所以我无法在我的 JSP 中使用这些值。获得值后,我需要在 JSP 中显示它们。

关于javascript - 如何使用 javascript 将值从父窗口传递到另一个 html 页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20219977/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com