+ Start a Discussion
coolKarnicoolKarni 

problem with window.close() in IE7

Hi,

I have opened a popup on a button click from a vfpage(parent page) , Within the popup page(child page) i am loading custom object values , within child page I have a button , when clicked on the button i should pass the values to parent page and close the child page automatically.

I am able to pass the values from child page to parent page succesfully , but The problem overhere is that i am unable to close the child window. I am using window.close() method in IE7 but it is not working can anyone help me out.

 

Thanks

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

I believe that only the page that opened the window can close it programmatically.

 

In my parent page, when I open the window I assign it to a variable (newWin).  Then when the user clicks the button in the popup page, it invokes a method in the parent page (closePopup).  This method checks newWin and, if its not null, executes newWin.close().

 

Here's the parent page snippets:

 

 

var newWin=null; function openPopup() { var url="/apex/MyPopup"; newWin=window.open(url, 'Popup','height=500,width=700,left=100,top=100,resizable=no,scrollbars=yes,toolbar=no,status=no'); } function closePopup() { if (null!=newWin) { newWin.close(); } }

 Then in the popup, I have:

 

 

<button type="button" onclick="CloseWindow();">Close Window</button> <script> function CloseWindow() { var winMain=window.opener; if (null==winMain) { winMain=window.parent.opener; } winMain.closePopup(); } </script>

 

 

 

 

 

All Answers

imuinoimuino
Can you post the javascript code?
bob_buzzardbob_buzzard

I believe that only the page that opened the window can close it programmatically.

 

In my parent page, when I open the window I assign it to a variable (newWin).  Then when the user clicks the button in the popup page, it invokes a method in the parent page (closePopup).  This method checks newWin and, if its not null, executes newWin.close().

 

Here's the parent page snippets:

 

 

var newWin=null; function openPopup() { var url="/apex/MyPopup"; newWin=window.open(url, 'Popup','height=500,width=700,left=100,top=100,resizable=no,scrollbars=yes,toolbar=no,status=no'); } function closePopup() { if (null!=newWin) { newWin.close(); } }

 Then in the popup, I have:

 

 

<button type="button" onclick="CloseWindow();">Close Window</button> <script> function CloseWindow() { var winMain=window.opener; if (null==winMain) { winMain=window.parent.opener; } winMain.closePopup(); } </script>

 

 

 

 

 

This was selected as the best answer
coolKarnicoolKarni

Hey Bob,

 

There it is, it works.

Thanks for the detailed solution bob, it solved my issue.

 

Thanks

shaan

coolKarnicoolKarni

Hi bob,

i have another requiremet i am not able to figure it out.

 

I am displaying a list of records within a pageblock table from a custom object..

My requirement is that for  a particular column in every row of the table have child records within that,so i need the expand and collapse property to be implemented within the table.such that whenclicked on the expand button the child records are displayed and when clicked again the records should hide.

Is that possible, or is there any other solution to achieve this??.

please let me know..

 

Thanks

bob_buzzardbob_buzzard

I've found that pageblocktable isn't particularly suited to that kind of thing - its very much aimed at displaying data from a single object.

 

Normally I end up doing this sort of thing using regular HTML tables, so that I have full control.

 

 

CoderCoder

Hi,

 

Can u share the code for passing the values from one visualforce page to another visualforce page.