<script src="scripts/jquery-1.4.1.js" type="text/javascript"></script> <script type="text/javascript"> $( function () { $.post("Handler.ashx", {}, function (data) { datafrom = data; }); } ); window.onbeforeunload = beforeUnload; window.onunload = unload; var datafrom = ""; var gotobaidu = false; function beforeUnload() { if (confirm(datafrom)) { } else { window.location.href = "http://www.baidu.com"; } } function unload() { } </script>