Skip to content Skip to sidebar Skip to footer

Why Do I Need To Write Alert() After Calling Window.open()?

I have a page index.jsp available at this link https://www.dropbox.com/s/0smy7nlcmilkqt4/index.jsp. This file contains a JavaScript method named validateloginForm() and is used to

Solution 1:

Because the code after window.open is executed immediately and the window isn't loaded at that point.

Using .alert is only a coincidence, if you dismissed the alert before the window was loaded, it still wouldn't work.

var newwin = window.open("validateUser.jsp?"+"empId="+empId+"&empPass="+empPass,"_parent","",""); 
newwin.onload = function() {
    //do stuff
};

Solution 2:

The browser will not wait for the URL referenced by window.open() to load before returning. Without the alert(), therefore, your "validateloginForm" function will just return right away.

Generally things in the browser are asynchronous. There's no way, in particular, to wait for window.open() to finish. You can have code in the page loaded into the new window call some function back on the parent ("opener") page, of course.

Post a Comment for "Why Do I Need To Write Alert() After Calling Window.open()?"