Click here to Skip to main content
15,910,358 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
This is regarding online exam..

Using Javascript i am able to open a popup window for taking test after selecting the domain from the dropdownlist (.net,java,oracle) from parent window.

JavaScript
function basicPopup(url)
{

popupWindow = window.open(url, 'popUpWindow',
'height=500,width=500,left=100,top=100,resizable=yes,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no, status=yes');

}


But how to close the parent window after a popup window is opened.
Posted
Updated 12-Sep-13 20:21pm
v2
Comments
Sergey Alexandrovich Kryukov 13-Sep-13 2:05am    
Doing so is really, really bad idea, by a number of reasons. You should rather review your UI design.
—SA
Adarsh chauhan 13-Sep-13 5:44am    
I agree..

As Sergey Alexandrovich Kryukov suggested, it is a bad idea. So, reconsider the design.

Still I would like to give the concept to you.
Refer - window.close[^].


To close the opened/child window

As you have assigned window to the variable popupWindow, so you can close the window with the help of that variable only.

We can say that popupWindow is an object, which is a instance of window class initialized using open method.

Use the following code to close the window.
JavaScript
popupWindow.close();



To close the parent window

Refer Solution 2 by Sergey Alexandrovich Kryukov.
 
Share this answer
 
v3
Comments
Maciej Los 13-Sep-13 3:42am    
5ed!
Thanks a lot Maciej Los... :)
Adarsh chauhan 13-Sep-13 5:45am    
completely agree... +5
Thanks a lot Adarsh... :)
Sergey Alexandrovich Kryukov 13-Sep-13 12:15pm    
"close" what? the problem is: OP wants to close the first window, the one which created the popup one. Please see my answer.
—SA
An important addition to Solution 1:

How to get the reference to the first window, the one you started with? You can use the property opener:
http://www.w3schools.com/jsref/obj_window.asp[^],
http://www.w3schools.com/jsref/prop_win_opener.asp[^].

But doing window.opener.close() is a really bad thing. The users don't expect such a nasty move from you. They don't keep a link to this window, they are sure they can always come back to this windows, but they won't be able to, they won't be able to come back by "Back" button. Not nice at all. I tell you, review your UI design.

—SA
 
Share this answer
 
Comments
Maciej Los 13-Sep-13 12:53pm    
+5!
Sergey Alexandrovich Kryukov 13-Sep-13 13:14pm    
Thank you, Maciej.
—SA
Sergey Alexandrovich Kryukov 14-Sep-13 20:02pm    
Thank you, Tadit.
—SA
Most welcome... :)
XML
<!DOCTYPE html>
<html>
<body>

<p>Click the button</p>

<button onclick="myFunction()">Try it</button>

<script>
function myFunction() {
   window.open("http://www.google.co.in", "", "width=1300, height=700");

     window.parent.close();
}
</script>

</body>
</html>
 
Share this answer
 

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