收集一些功能与问题(一),请大家不要拍啊!
有一些JS代码是从网上得到后进行处理的。
1、用SilverLight3时,有一次在启动页面(html页或aspx)为了对齐代码按一下Ctrl+K+D,运行后发现就SilverLight3主界面产生垂直滚动条,非常奇怪,不知什么原因。通过新建一个对比结果如下。(不是SilverLight4是否还会存在)
(1)原始代码(引用对象部份):
<body> <form id="form1" runat="server" style="height: 100%;"> <div id="silverlightControlHost"> <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%"> <param name="source" value="ClientBin/Temp.xap" /> <param name="onerror" value="onSilverlightError" /> <param name="background" value="white" /> <param name="minRuntimeVersion" value="3.0.40818.0" /> <param name="autoUpgrade" value="true" /> <a href="../Silverlight/Silverlight.exe" style="text-decoration: none;"> <img src="../Silverlight/Silverlight.jpg" alt="获取 Microsoft Silverlight插件" style="border-style: none" /> </a> </object><iframe id="_sl_historyFrame" style='visibility: hidden; height: 0; width: 0; border: 0px'></iframe></div> </form></body>
<body> <form id="form1" runat="server" style="height: 100%;"> <div id="silverlightControlHost"> <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%"> <param name="source" value="ClientBin/Temp.xap" /> <param name="onerror" value="onSilverlightError" /> <param name="background" value="white" /> <param name="minRuntimeVersion" value="3.0.40818.0" /> <param name="autoUpgrade" value="true" /> <a href="../Silverlight/Silverlight.exe" style="text-decoration: none;"> <img src="../Silverlight/Silverlight.jpg" alt="获取 Microsoft Silverlight插件" style="border-style: none" /> </a> </object> <iframe id="_sl_historyFrame" style='visibility: hidden; height: 0; width: 0; border: 0px'> </iframe> </div> </form></body>
function JsWebService() { this.ServerURL = "../WebService/"; //服务器web路径 this.NameSpace = "http://A9.ERP/"; //Web命名空间 function createXMLHttpRequest() { var xmlHttp; if (window.ActiveXObject) { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); //IE } else if (window.XMLHttpRequest) { //非IE xmlHttp = new XMLHttpRequest(); } return xmlHttp; } //服务名、成员名、参数名集合、参数值集合、回调函数(若希望回调结果) this.ServiceRequest = function(ServiceName, MethodName, ParamNames, ParamValues, CallBack) { var xmlHttp = createXMLHttpRequest(); var SOAPString = GetSOAPHeader(this.NameSpace, MethodName, ParamNames, ParamValues); var SOAPActionHeader = this.NameSpace + MethodName; xmlHttp.open("POST", this.ServerURL + ServiceName, true); if (CallBack != null) { xmlHttp.onreadystatechange = function() { if (xmlHttp.readyState == 4) { if (xmlHttp.status == 200) { CallBack(xmlHttp); } } }; } xmlHttp.setRequestHeader("Content-Type", "text/xml"); xmlHttp.setRequestHeader("SOAPAction", SOAPActionHeader); xmlHttp.send(SOAPString); } function GetSOAPHeader(NameSpace, MethodName, ParamNames, ParamValues) { var SOAPString = ""; SOAPString += "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n" SOAPString += "<soap:Body>\n"; SOAPString += "<" + MethodName + " xmlns=\"" + NameSpace + "\">\n"; if (ParamNames != null) { for (var i = 0, j = ParamNames.length; i < j; i++) { SOAPString += "<" + ParamNames[i] + ">" + ParamValues[i] + "</" + ParamNames[i] + ">\n"; } } SOAPString += "</" + MethodName + ">\n"; SOAPString += "</soap:Body>\n"; SOAPString += "</soap:Envelope>\n"; return SOAPString; }}
<script type="text/javascript" src="JsWebService.js"></script> <script type="text/javascript"> if (window.Event) { window.onbeforeunload = function(event) { UserAbandon(); } } else { window.onbeforeunload = function() { UserAbandon(); } } function UserAbandon() { var UserAbandon = new JsWebService(); UserAbandon.ServiceRequest("UserService.asmx", "UserAbandon", null, null, null); } </script>
<%@ Page Language="C#" AutoEventWireup="true" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>客户关系管理系统</title> <style type="text/css"> html, body { height: 100%; overflow: auto; } body { padding: 0; margin: 0; } #silverlightControlHost { height: 100%; text-align: center; } </style> <script type="text/javascript" src="JsWebService.js"></script> <script type="text/javascript"> if (window.Event) { window.onbeforeunload = function(event) { UserAbandon(); } } else { window.onbeforeunload = function() { UserAbandon(); } } function UserAbandon() { var UserAbandon = new JsWebService(); UserAbandon.ServiceRequest("UserService.asmx", "UserAbandon", null, null, null); } </script> <script type="text/javascript" src="Silverlight.js"></script> <script type="text/javascript"> 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 = "应用程序中未处理的错误 " + 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"; } alert(errMsg); } </script></head><body> <form id="form1" runat="server" style="height: 100%;"> <div id="silverlightControlHost"> <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%"> <param name="source" value="ClientBin/Temp.xap" /> <param name="onerror" value="onSilverlightError" /> <param name="background" value="white" /> <param name="minRuntimeVersion" value="3.0.40818.0" /> <param name="autoUpgrade" value="true" /> <a href="../Silverlight/Silverlight.exe" style="text-decoration: none;"> <img src="../Silverlight/Silverlight.jpg" alt="获取 Microsoft Silverlight插件" style="border-style: none" /> </a> </object><iframe id="_sl_historyFrame" style='visibility: hidden; height: 0; width: 0; border: 0px'></iframe></div> </form></body></html>