Javascript 是否从子页面访问父页面变量?
我想将值从子页面传递到父页面: 父页面脚本:Javascript 是否从子页面访问父页面变量?,javascript,html,asp.net,parent-child,return-value,Javascript,Html,Asp.net,Parent Child,Return Value,我想将值从子页面传递到父页面: 父页面脚本: <script type="text/javascript"> var popup; function SelectName() { popup = window.open("SelDestination.aspx", "Select", "width=500,height=300"); popup.focus(); return false; } </scri
<script type="text/javascript">
var popup;
function SelectName() {
popup = window.open("SelDestination.aspx", "Select", "width=500,height=300");
popup.focus();
return false;
}
</script>
var弹出窗口;
函数SelectName(){
popup=window.open(“SelDestination.aspx”,“Select”,“width=500,height=300”);
popup.focus();
返回false;
}
在子页面上:
<asp:Button ID="btnSelect" runat="server" CssClass="button" Text="انتخاب" OnClientClick="SetName();" />
子页面脚本为:
<script type="text/javascript">
function SetName() {
if (window.opener != null && !window.opener.closed) {
var ddlName = window.opener.document.getElementById("txtDes");
//var e = document.getElementById("<%=ddlOffice.ClientID %>");
ddlName.value = "Hi";
}
window.close();
}
函数SetName(){
if(window.opener!=null&&!window.opener.closed){
var ddlName=window.opener.document.getElementById(“txtDes”);
//var e=document.getElementById(“”);
ddlName.value=“Hi”;
}
window.close();
}
但它不能正常工作(我有一个运行时错误:ddlname为null或未定义)
有没有关于如何修复它的想法?制作一个javascript文件并在head中执行此操作:
<script src="path/to/ye/js"></script>
记住在这两个站点都要这样做。
然后将此变量添加到javascript文件。@Ganesh_Devlekar它只是一个变量名。@Masoodtav在子页面脚本上,删除opener,保留:
window.document.getElementById(“txtDes”)代码>@Superdrac它不能正常工作!当然“txtDes”在我的家长页面上!请确认错误消息是否与您看到的完全一致。您有这个变量ddlName,但在错误中它建议使用不同的变量名ddlName。这是您的拼写错误,还是在代码中?@HappyHamburger“ddlName”只是变量的名称。我在这里复制错误:0x800a138f中第11行第18列的未处理异常-JavaScript运行时错误:无法设置未定义或空引用的属性“value”