silverlight 退出系统(关闭当前网页),通过调用JS

   

silverlight 退出系统(关闭当前网页),通过调用JS

 

特别鸣谢“四川省计算机研究院科技人才培训中心中国顶级RIA、嵌入式培训机构”提供图片

成都市成科西路3号 
传真:028-68187983
网站: http://www.tccxfw.com/jiaoyu.html

 

silverlight 退出系统(关闭当前网页),通过调用JS_第1张图片

 

在退出的silverlight退出按钮下添加下列代码

private void btnSystemExit_Click(object sender, RoutedEventArgs e)
        {
            if (MessageBox.Show("确认退出系统?", "提示",
MessageBoxButton.OKCancel) == MessageBoxResult.OK)
            {
                //Silverlight调用JS
                ScriptObject Show = HtmlPage.Window.GetProperty("closeWin") as ScriptObject;
                Show.InvokeSelf();
            }

        }
 

 在加载.xap的aspx页面中添加下列代码

<script type="text/javascript" src=\'#\'" /script>
    <script type="text/javascript">
        function closeWin() {
            //IE
            //window.open('', '_parent', '');//弹出询问窗体
            window.opener = null; //不弹出提示
            window.close();
        }
    
        function onSilverlightError(sender, args) {
            var appSource = "";
            if (sender != null && sender != 0) {
              appSource = sender.getHost().Source;
            }
           
            var errorType = args.ErrorType;
            var iErrorCode = args.ErrorCode;

            if (errorType == "ImageError" || errorType == "MediaError") {
              return;
            }

            var errMsg = "Silverlight 应用程序中未处理的错误 " +  appSource + "\n" ;

            errMsg += "代码: "+ iErrorCode + "    \n";
            errMsg += "类别: " + errorType + "       \n";
            errMsg += "消息: " + args.ErrorMessage + "     \n";

            if (errorType == "ParserError") {
                errMsg += "文件: " + args.xamlFile + "     \n";
                errMsg += "行: " + args.lineNumber + "     \n";
                errMsg += "位置: " + args.charPosition + "     \n";
            }
            else if (errorType == "RuntimeError") {          
                if (args.lineNumber != 0) {
                    errMsg += "行: " + args.lineNumber + "     \n";
                    errMsg += "位置: " +  args.charPosition + "     \n";
                }
                errMsg += "方法名称: " + args.methodName + "     \n";
            }

            引发新错误(errMsg);
        }
         

 


    </script>

你可能感兴趣的:(js,职场,silverlight,休闲,退出系统)