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();
}
}, 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:
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:
opener.location.reload();
window.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(){
opener.location.reload();
window.close();
}
Hope it helps.