I have a form I like to open in pop up windows when user close my website or browser .. I want like to take feedback from users by pop up form like "give your comments how we can improve our website" and then with php I will submit the form and admin of website will get users feedback.
I am stuck here and fail to find JS code that open popup form on close browser event.
can any one help me out.
What have you tried so far?
Here is one approach, but user may be able to disable it, and may be blocked by popup blockers (not to mention a whole ethics debate, but hey... you asked):
From main page:
<script>
window.onbeforeunload = function()
{
var url = "feedback_form.html";
window.open(url, "_blank", "toolbar=yes, scrollbars=yes, resizable=yes, top=500, left=500, width=400, height=400");
};
</script>
Confirmed that this code works in IE9, Chrome, and Firefox with the popup blocker disabled.
Usability concerns and other thoughts:
Stop wanting to do that. Imagine how horrible the user experience would be for the whole web if it were possible to do that. If it was already possible, a rampaging mob with flaming torches and pitchforks would demand it be fixed immediately. Be thankful that there is no satisfactory answer to your question.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.