如何在ASP.NET中使用jquery / javascript关闭子窗口后重新加载/刷新父窗口? [英] How to reload/refresh the parent window after child window closed using jquery/javascript in ASP.NET?

查看:110
本文介绍了如何在ASP.NET中使用jquery / javascript关闭子窗口后重新加载/刷新父窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,





我在ASP.NET中有一个网页构建和AddNew按钮点击我正在使用jquery打开/提示新窗口添加新记录。



当我点击AddNew Button时,在子窗口提示后,父窗口闪烁,我想停止闪烁子窗口打开后的父窗口。



现在,添加新记录后,子窗口/提示窗口将关闭,但父窗口没有重新加载/刷新。



我尝试过:



Hi guys,


I have a webpage build in ASP.NET and AddNew button click i'm using jquery to open/prompt new window to add new records.

And when i clicked on AddNew Button, after child window prompt, the parent window is getting blink, i want to stop blinking the parent window after the child window gets open.

Now, after adding new record, the child/prompted window will get closed but the parent window is not getting reload/refresh.

What I have tried:

<script type="text/javascript">
    function JobDone(id) {
       // alert(id);
        var win = window.open('WorkshopJobDone.aspx?id=' + id, 'WorkshopJobDone', 'width=350,height=300,scrollbars=no,toolbar=no,screenx=0,screeny=0,location=no,titlebar=no,directories=no,status=no,menubar=no,scrollbars=no');
        var timer = setInterval(function () {
            if (win.closed) {
                alert("closed");
                clearInterval(timer);
                window.location.reload(); // Refresh the parent page
            }
        }, 1000);
    }
</script>





任何人都可以帮助我,如何解决这个问题。




谢谢



can any one please help me, how to solve this.


Thanks

推荐答案

你的代码搞砸了!你想要达到的目标尚不清楚。我假设您正在尝试实现非常着名的Open-A-Popup-AddRecord-CloseIt-RefreshParentWindow任务。现在,基于我的假设,让我们逐行看看你的代码。



这是打开弹出窗口的代码。足够好(但我怀疑)

Your code is all sort of messed up! What are you trying to achieve is not clear. I am assuming you are trying to achieve the very famous Open-A-Popup-AddRecord-CloseIt-RefreshParentWindow task. Now, based on my assumption, lets take a look at your code line-by-line.

This is the code to open a popup window. Good enough(but I doubt)
var win = window.open('WorkshopJobDone.aspx?id=' + id, 'WorkshopJobDone', 'width=350,height=300,scrollbars=no,toolbar=no,screenx=0,screeny=0,location=no,titlebar=no,directories=no,status=no,menubar=no,scrollbars=no');





在同一页面(我假设)你有:



On the same page(I assume) you have:

var timer = setInterval(function () {
            if (win.closed) {
                alert("closed");
                clearInterval(timer);
                window.location.reload(); // Refresh the parent page
            }
        }, 1000);





你知道setInterval()的作用吗?它以重复的指定间隔重复语句。现在,您正在使用以下代码行检查窗口是否仍然打开:



Do you know what setInterval() does? It repeats the statements in the specified intervals REPEATEDLY. Now, you are checking if the window is still opened or not using this line of code:

if (win.closed)



它会给你一个假值,因为你的子窗口已经存在了。顶部的樱桃,即使窗户关闭,你每秒都会进行这项检查!



现在,在我建议您先做什么之前,你必须访问< a href =http://www.w3schools.com/jsref/prop_win_closed.asp>这个 [ ^ ]和 [< a href =http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_win_setintervaltarget =_ blanktitle =New Window> ^ ]了解您的代码正在做什么。



完成后,请按照以下步骤操作:

1.使用父页面上的脚本打开子窗口(您已经拥有在那里)。

2.删除检查窗口是否关闭的代码。你不需要它。

3.当您完成从子窗口添加新记录后,请调用以下语句:


and it is giving you a false value because your child window is already there. Cherry on the top is you are performing this check every second even if the window is closed!

Now, before I suggest you what to do first you have to visit this[^] and this[^] to understand what your code is doing.

Now when you are done, follow these steps:
1. Open child window using the script on your parent page(you already have it there).
2. Get rid of the code that checks if the window is closed or not. You don't need it, in any way.
3. When you are done with adding a new record from you child window call these statements:

opener.location.reload(); //This will refresh parent window.
window.close(); //Close child window. You may also use self.close();



以上两行将写在子页面上。也许在点击按钮上。在数据库中添加记录并调用脚本。例如:


The above two lines will be written on the child page. Maybe on a buttons click. Add a record in the DB and call the script. For example:

<input type="button" onclick="AddRecord()" value="Save Record" />




function AddRecord(){
//Add newrecord.
opener.location.reload(); //This will refresh parent window.
window.close(); //Close child window. You may also use self.close(); 
}





希望有所帮助。



Hope it helps.


这篇关于如何在ASP.NET中使用jquery / javascript关闭子窗口后重新加载/刷新父窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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