将邮政编码带到新窗口中的新字段

发布于 2024-10-09 11:26:26 字数 703 浏览 5 评论 0原文

我的 html 字段上有一个只读字段,其名称为 _Dataaddr_postcode 我现在需要捕获此数据并将其传递到一个新窗口中,该窗口加载另一个文件 (proxcomp.asp) 并使用此页面上的字段中的数据字段的 ID 为 inpAddr。

到目前为止我有这段代码

<script type="text/javascript">
var pcodeStart = document.getElementbyId("_Dataaddr_postcode");
var newWindow;
function makeNewWindow( ) {
if (!newWindow || newWindow.closed) {
newWindow = window.open("../hpwprox/proxcomp.asp","sub","status=0,title=0,height=600,width=800");
setTimeout("writeToWindow( )", 50);
} else if (newWindow.focus) {
newWindow.focus( );
}
}
</script>
<input type="button" value="Create New Window" onclick="makeNewWindow();" />

有人可以告诉我如何用一些示例代码来实现这一点吗?

谢谢

贾斯汀。

I have a read only field on a html field which has a name of _Dataaddr_postcode I now need to capture this data and pass it into a new window which loads another file (proxcomp.asp) and use the data in a field on this page the field has an ID of inpAddr.

I have this code so far

<script type="text/javascript">
var pcodeStart = document.getElementbyId("_Dataaddr_postcode");
var newWindow;
function makeNewWindow( ) {
if (!newWindow || newWindow.closed) {
newWindow = window.open("../hpwprox/proxcomp.asp","sub","status=0,title=0,height=600,width=800");
setTimeout("writeToWindow( )", 50);
} else if (newWindow.focus) {
newWindow.focus( );
}
}
</script>
<input type="button" value="Create New Window" onclick="makeNewWindow();" />

Can someone tell me how to achieve this with some sample code?

Thanks

Justin.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦里梦着梦中梦 2024-10-16 11:26:26

仅将该一个字段作为表单输入传递到服务器端脚本:

var genForm = document.createElement("form");
genForm.target = "sub";
genForm.method = "get"; // or "post" if appropriate
genForm.action = "../hpwprox/proxcomp.asp";

var genInput = document.createElement("input");
genInput.type = "hidden";
genInput.name = "inpAddr";
genInput.value = pcodeStart.value;
genForm.appendChild(genInput);

document.body.appendChild(genForm);

if(!newWindow || newWindow.closed) {
    window.open("", "sub", "status=0,title=0,height=600,width=800");
} else if(newWindow.focus) {
    newWindow.focus();
}

genForm.submit();

如果您希望使用客户端代码而不是服务器端代码在弹出窗口中设置文本框,则需要从弹出窗口中执行此操作向上窗口以避免您否则会添加的延迟以及页面加载时间相互“竞争”的情况。在 JavaScript 中,全局变量是它们所在的窗口对象的属性,并且 window.opener 给出打开此窗口的窗口。请注意,由于同源政策,两者Windows 的 URL 中需要具有相同的协议、主机名和端口号。

// Using the variable referring to the text box:
document.getElementById('inpAddr').value = window.opener.pcodeStart.value;

// Or even using getElementById directly:
document.getElementById('inpAddr').value = window.opener.document.getElementById('inpAddr').value

如果您愿意,可以省略 window.openerwindow. 部分,前提是您没有使用名为 opener 的变量。

Passing just that one field as a form input to the server-side script:

var genForm = document.createElement("form");
genForm.target = "sub";
genForm.method = "get"; // or "post" if appropriate
genForm.action = "../hpwprox/proxcomp.asp";

var genInput = document.createElement("input");
genInput.type = "hidden";
genInput.name = "inpAddr";
genInput.value = pcodeStart.value;
genForm.appendChild(genInput);

document.body.appendChild(genForm);

if(!newWindow || newWindow.closed) {
    window.open("", "sub", "status=0,title=0,height=600,width=800");
} else if(newWindow.focus) {
    newWindow.focus();
}

genForm.submit();

If you wish to use client-side code to set a textbox in the pop-up rather than server-side code, you need to do it from the pop-up window to avoid the delay you would add otherwise and the page's load time from "racing" each other. In JavaScript, global variables are properties of the window object they exist inside of, and window.opener gives the window that opened this one. Note that because of the same-origin policy, the two windows need to have the same protocol, hostname, and port number in their URLs.

// Using the variable referring to the text box:
document.getElementById('inpAddr').value = window.opener.pcodeStart.value;

// Or even using getElementById directly:
document.getElementById('inpAddr').value = window.opener.document.getElementById('inpAddr').value

You can omit the window. part of window.opener if you want to, provided that you are using no variable called opener.

戈亓 2024-10-16 11:26:26

也许这样做:

newWindow.document.getElementById('inpAddr').value = pcodeStart;

或者从打开的窗口:

document.getElementById('inpAddr').value = opener.document.getElementbyId("_Dataaddr_postcode").value;

请阅读这篇精彩的文章

Maybe doing this:

newWindow.document.getElementById('inpAddr').value = pcodeStart;

Or from the open window:

document.getElementById('inpAddr').value = opener.document.getElementbyId("_Dataaddr_postcode").value;

Please read this great article!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文