Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Posted
Updated 4-May-16 4:35am
v2
Comments
Karthik_Mahalingam 4-May-16 6:43am    
post your AddNew button mark up code

1 solution

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)
JavaScript
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:
JavaScript
var timer = setInterval(function () {
            if (win.closed) {
                alert("closed");
                clearInterval(timer);
                window.location.reload(); // Refresh the parent page
            }
        }, 1000);


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:
JavaScript
if (win.closed)

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:
JavaScript
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:
HTML
<input type="button" onclick="AddRecord()" value="Save Record" />

JavaScript
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.
 
Share this answer
 
Comments
abdul subhan mohammed 5-May-16 3:00am    
Thank you very much, may God bless you. Hats off!
Zafar Sultan 5-May-16 3:21am    
You are welcome.
sajeer binsaleem 19-Jul-22 5:34am    
So how the parent window understands the child window successfully closed or not?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900