Close the popup on click on the page
Is there a way to close Advanced Layer Popup when the user clicks outside the popup window on the page?
Answer:
This can be achieved with the following work around:
1. Add id to your link that starts the popup.
2. Also do not forget to set Popup Name field into Advanced Layer Popup dialog
See the image below:
3. Add the following JavaScript to your page and replace link_ID with your link Id (which you set in step 1) and Window_Name with the Popup Name (which you have set in step 2):
<script type="text/javascript">
document.onclick = function(e){
if (!e && event) e = event;
if ( !e.target && e.srcElement ) {
e.target = e.srcElement;
}
if((e.target.id.indexOf("dmxPopup")==-1)&&(e.target.id!="link_ID"))
{
//Close Popup
cDMXPopupWindow.closeWindow('dmxPopupWindow_Name');
}
}
</script>
After, following all the step the code may look like this:
<a id="Register" href="#" target="_blank" onclick="dmxAdvLayerPopup('Registration','email_sub_form.asp','Register','',
'OS_Look','center','center',300,200,0,true,false,false,0,'','Linear',2,true,
'','',0,false,'',1,5,true,false,'#FFFFFF');return document.MM_returnValue">Registration</a>
<script type="text/javascript">
document.onclick = function(e){
if (!e && event) e = event;
if ( !e.target && e.srcElement ) {
e.target = e.srcElement;
}
if((e.target.id.indexOf("dmxPopup")==-1)&&(e.target.id!="Register"))
{
//Close Popup
cDMXPopupWindow.closeWindow('dmxPopupRegister');
}
}
</script>
Note: I have used Register both for the link id and for the Popup Name.
DISCLAIMER:
This is extra complimentary content which purpose is to show
additional usage that is not part of the product, i.e. it suggests tips
for extending the functionality of the product by the users themselves.
DMXzone does not take responsibility to support the suggested
content to be fully compatible and working as intended and does not
provide support for extended functionality which is not included in the
current release of the extension.
It is highly recommended that only more advanced developers use it.
Comments
Multiple Popups
Click anywhere to close, overlay working?
I too would like to have this work for more than one popup, while keeping the overlay feature functional.
Thanks!
Would be great to have this to work onload
Hello,
Firstly thank you for your code.
It would be great if you had it so it could be used in an onload kida thing. for instance. I have a popup layer with an insert server behaviour, when it is submitted it redirects the user to a thankyou page inside the popup. I would like to be able to make this thank you page only appear for 4 seconds then have the pop up layer close. on doing that then have the parent page refresh.
Hope your well and hope you dont mind me begging for an example lol
cheers
kenny
You must me logged in to write a comment.