我有以下JavaScript代码 -
function addOnClickEventHandler()
{
var userNameElement = document.getElementById("currentUser");
var userName = userNameElement.value; // send this value to "chatWindow"
window.open("chatWindow.html", "Chat Window", "resizable=0,width=700,height=600");
}
现在,如何将userName的值发送到“chatWindow”?此外,如何在发送后访问此值?
答案 0 :(得分:1)
在打开的窗口中,您可以按如下方式查询父窗口:
var oWinCaller = top.opener;
通过此参考,您可以在新窗口打开时从打开的窗口中获得所需的任何内容。
答案 1 :(得分:0)
你可以尝试
window.open("chatWindow.html?id=1", "Chat Window", "resizable=0,width=700,height=600");
To Read Argument create js function in opening page and create following function
function getArgs() {
var args = new Object();
var query = location.search.substring(1);
var pairs = query.split("&");
for (var i = 0; i < pairs.length; i++) {
var pos = pairs[i].indexOf('=');
if (pos == -1) continue;
var argname = pairs[i].substring(0, pos);
var value = pairs[i].substring(pos + 1);
args[argname] = unescape(value);
}
return args;
}
然后用
var args = getArgs();
var hid = args.id;