function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
PremanathPremanath 

close popup window when we click on outside popup window(urgent please)

Hi All,

 

Create one javascript button on contact , when we click on that button the popupwindow should be come.

And when we click on outside window popup window should be close.

 

I got some problm with my code , it doesn't work properly , plz cheak it...

 

{!REQUIRESCRIPT("/soap/ajax/8.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/15.0/apex.js")}

var url="/apex/commentspage?&id=" +" {!Contact.Id}";

newWin=window.open(url, 'Popup','height=500,width=600,left=100,top=100,resizable=yes,scrollbars=no,toolbar=no,status=no');
if (newWin.focus())
{
self.focus();
}
window.onblur=function()
{
newWin.close();
};

 

 

 

 

please solve my problm i can appriciate very much........

Thank you

Best Answer chosen by Admin (Salesforce Developers) 
PremanathPremanath

I got solution for this one

 

window.top.close();

 

it's working now

 

thank you guys 

All Answers

JitendraJitendra

Hi instead of 

 

window.onblur=function()
{
newWin.close();
};

 

write this :

 

newWin.onblur=function()
{
  newWin.close();
};

 Or this:

 

newWin.onblur= newWin.close();

 


Riptide CloudRiptide Cloud

We have a free tool you can use for pop-ups it is located here. http://www.riptidecloud.com/products/popup-alerts

PremanathPremanath

Hi Jitendra,

 

Thanks for you reply...

Both Are not Working .

If we click another tab it can work.

But if we click same window outside of popup it doesn't work at all.

 

Please make it guys,...

JitendraJitendra

Hi,

Please find Working Sample HTML code:

 

Test.html


<html>
<head>
</head>

<body>
<input type="button" value="Open Google" onclick="OpenWindow()" />

<script type="text/javascript">

function OpenWindow()
{
	var url="Test2.html";
	newWin=window.open(url, 'Popup','height=500,width=600,left=100,top=100,resizable=yes,scrollbars=no,toolbar=no,status=no');
	if (newWin.focus())
	{
	self.focus();
	}
}
</script>

</body>
</html>

 

Test2.html


<html>
<head>
</head>

<body>
<input type="button" value="Open Google" />

<script type="text/javascript">
    function closeme()
    {  
        window.close();
    }
    window.onblur=closeme;
</script>

</body>
</html>

 

You can see, the code to close window is written on popup window itself.

 

 

 

PremanathPremanath

Hi thank for you reply

 

I want to create javascript button..

 

We have write the code on

 

setup-->contact-->buttons and links

Javascript button

 

We have to write code here...

 

Please test it..

JitendraJitendra

Hi,

 

If you can write small code in Child window page then your problem can be solved. However i tried to achieve but unfortunately i am not able to perform it. I have opened the thread at stackoverflow, let hope for answer there because it is actualy related to javascript.

 

http://stackoverflow.com/questions/11687375/close-child-window-from-parent-onblur-using-javascript

PremanathPremanath

I got solution for this one

 

window.top.close();

 

it's working now

 

thank you guys 

This was selected as the best answer
JitendraJitendra

Thanks for sharing the solution.