以邮政code到新领域新窗口 [英] Take Postcode to New Field in New Window

查看:184
本文介绍了以邮政code到新领域新窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对其中有_Dataaddr_post code现在我需要捕获这些数据,并把它传递到它加载另一个文件(proxcomp.asp)的新窗口的名称的HTML领域的只读字段,并使用数据在这个页面上的场场都有inpAddr的ID。

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.

我有这样的code到目前为止

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();" />

谁能告诉我如何与一些样本code来实现这一目标?

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

感谢

贾斯汀。

推荐答案

传递只是一个字段作为输入到服务器端脚本形式:

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();

如果您希望使用客户端code将在弹出,而不是服务器端code一个文本框,您需要从弹出的窗口中这样做是为了避免耽误您将从赛车对方,否则添加和网页的加载时间。在JavaScript中,全局变量是他们的内部存在的窗口对象的属性和 window.opener 给出了打开这个窗口。请注意,由于同源策略,两个窗口需要具有相同的协议,主机名,并在他们的网址端口号

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

您可以省略窗口。 window.opener 的一部分,如果你想,只要​​你正在使用没有变量名为揭幕战

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

这篇关于以邮政code到新领域新窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆