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
LakshmanLakshman 

How to close a popup window when clicked outside popup

Hi All,

 

I have a VFP which has a button which on clicked opens a new popup having different VFP. To open the popup I have used window.open method of JS.

I want that when I click outside the popup it should get closed. Any thoughts/ideas to it are welcomed.

I want you to know that I have used this function:

 

<script>
window.onblur=function(){
self.close();
}; 
</script>

 

 

Now whenever I click on popup window itself, it gets closed. LOL, this is weird.

Waiting for your replies.

 

Regards,

Lakshman.

Shashikant SharmaShashikant Sharma

You can use a trick

 

Set a var 

 

<script>
var onBlurCount = 0;
window.onblur=function(){
if(onBlurCount > 0)
{
   self.close();
}
else
{
  onBlurCount = 1;
}
}; 
</script>

 Just try this,

If any issue you please let me know,

 

One more thing I think showModalDialog is also usefull for you as it disable parent window.

http://javascript.gakaa.com/window-showmodaldialog-4-0-5-.aspx

 

 

LakshmanLakshman

Hi Shashikant,

 

Thanks for your reply.

I am able to achieve my goals by my above script in all browsers except IE. In IE what happens you know, whenever I click on any element of the popup page, the pop up gets Closed while in other browsers it doesn't i.e... It behaves normal as I expected.

Regarding your next suggestion, I have first tried showModadialog but there were some issues in IE so I switched to window.open. But now I am facing this new weird issue.

 

This is my popup code:

 

<SCRIPT language="javascript">
window.onblur=function()
{
self.close();
};
</script>
<select>
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="mercedes">Mercedes</option>
  <option value="audi">Audi</option>
</select>
<textarea style="width: 628px; height: 404px;" cols="93" id="p7" maxlength="32000" name="p7" rows="15" type="text" ></textarea>

Just try this code in IE you will find that whenever you click on drop down arrow of select list, the pop will get close. For other browsers it would just work absolutely FINE.

Let me know your thoughts for making this work in IE.

Thank you!

 

Regards,

Lakshman.

 

sjain1.2523113033806995E12sjain1.2523113033806995E12

have you tried the window.top.close() instead of self.close().Tryout this one and let me know if there is any issues..

LakshmanLakshman

I tried window.top.close()....... works fine in all browsers except IE. I am facing same problems as earlier.

 

Regards,

Lakshman