测试通过,供自己学习吧!只有前台代码,无后台代码。新建一个WebForm1.aspx页面,如下: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>必优博客 实现Javascript退出页面弹出对话框</title> </head> <mce:script type="text/javascript"><!-- window.onbeforeunload = function(){ return "哎!你妈喊你回家吃饭了,您确定要回去吗?"; } // --></mce:script> <body> <h2>直接关闭窗口或按F5刷新页面</h2> <a href="http://www.hao123.com" mce_href="http://www.hao123.com">查看使用说明</a> </body> </html>