We\'re tryin to implement some kind of feedback, which I saw in MSDN web-site. More concrete when user first enters to our site, I want to show a pop-up which will ask user to l
I dare to say this is not possible. In the old days when a developer wanted to cut user's fingers off they removed browser chrome completely, so users were left to clicking only links within the border-less window. This was (almost) the only way for users to close the window to provide a button close.
But these days are gone. You can't hide browser away anymore due to security reasons. And I personally think that's very bad practice as well.
You can only detect whether someone is leaving your page. But you can't know for sure whether they are leaving due to doing some action within your page (unless you add functionality to every action on it) or they've maybe clicked back or even forward browser history button. Not to mention they've written a web address in the address bar or even searched Google via search bar... I don't even want to think about all the possible browser plugins/extensions that may redirect users to whatever page they like. What about browser upgrades? Will they provide some sort of special functionality you can't think about? Well too many variables to this equation for my taste.
When one wants to leave your site, they want to leave it. Even though you'd present them a survey, they could just as easily click close or go elsewhere (maybe even happier to close it). So there is no obvious reason for you to present this survey on user leaving.
Even Microsoft does it on page load. And if someone says Yes they are presented with participation survey right away. Not waiting until they leave the site...
The only reason is of course that you want to collect data after they've used your site/app. Well bad luck. Unless you track users in which case you could present them survey on their re-visit, but they are more loyal already so results would be biased.
Otherwise people just won't fill them up.
The problem is, it's not really possible to know definitively when someone is "leaving" your web site.
You could try to capture via Javascript when they are navigating away from pages on your site, but even if you do that, and you know they are going to a page on some other site, you could easily get 'false positives" there if, for example, someone has your site open in multiple tabs.
I think that is the reason you usually find such "feedback popups" either come when you first visit a site, or come during some process in the application itself - such as at the end of a shopping cart purchase.
Without hindsight, there really is no way to know what the last page someone is visiting on your site will be.
And in the comments, others have noted that this type of behavior would likely annoy your users... even if they opted-in to it somehow upon visiting the site.