Window.opener不会将值返回到父页面 [英] Window.opener not returning value to parent page

查看:255
本文介绍了Window.opener不会将值返回到父页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我对ASP.Net和JavaScript相当陌生.我有一个父页面,该页面使用JavaScript window.open打开一个弹出页面.弹出窗口将允许用户获取文件夹路径,一旦选中该窗口,它将在文本框中显示文件夹路径.当我单击确定时,子页面将关闭并在父页面的文本框中显示文件夹路径.问题是它没有将值返回到父页面.

这是我的代码:

javascript:

Hi,

I am quite new with ASP.Net and JavaScript. I have a parent page that opens a pop-up page using a JavaScript window.open.The pop-up window will allow user to get the folder path,once selected it will display the folder path in a text box. And when I click OK, the child page will close and display the folder path into the parent page''s textbox.The problem is it does not return the value to the parent page.

Here is my code:

javascript:

function SelectAndClose()
        {
            txtValue = document.getElementById('_browseTextBox');
            if ((window.opener != null) && (window.opener && !window.opener.closed))
            {
                   window.opener.InvokeParent(txtValue.value);
            }
                window.close();
                return false;
        }



aspx:



aspx:

<asp:Button ID="_selectButton" Text= "OK" runat="server" Width="138px" OnClientClick="SelectAndClose();">



任何帮助将不胜感激.

感谢



Any help is greatly appreciated.

Thanks

推荐答案

您确定您有一个带clientId _browseTextBox的文本框吗? asp.net呈现ID时更改ID.
要调试此功能,我会添加一些警报,以查看代码是否按预期运行.添加一个警报以查看是否可以从_browseTextBox读取值,并添加一个警报以查看是否触发了函数InvokeParent.并警告您是否返回true(window.opener!= null)
调试javascript时,开发人员工具也很有用.按下F12:)
Are you sure you have a textbox with clientId _browseTextBox? asp.net change id''s when they render.
To debug this i would add some alerts to see if the code behave as I expect. Add an alert to see if you can read the value from _browseTextBox and an alert to see if the function InvokeParent are fired. And and alert to see if your if''s return true (window.opener != null)
Developers tools are also useful when debugging javascript. Hit F12 :)


你好,

尝试替换此行

txtValue = document.getElementById(''_ browseTextBox'');



txtValue = document.getElementById(''<%= _ browseTextBox.ClientID%>'');
Hello,

Try replace this line

txtValue = document.getElementById(''_browseTextBox'');

with

txtValue = document.getElementById(''<%=_browseTextBox.ClientID %>'');


这篇关于Window.opener不会将值返回到父页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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