Created
February 15, 2013 12:19
-
-
Save yetanotherchris/4960078 to your computer and use it in GitHub Desktop.
Silverlight: custom error messages using jQuery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Silverlight Installation example</title> | |
<style type="text/css"> | |
body { background:#FFFFFF;font-family:Verdana,sans-serif;text-align:center;} | |
h1 { font-size:1.2em;} | |
#install-container | |
{ | |
background: #ABABAB; | |
width:500px; | |
height:500px; | |
border:2px solid green; | |
margin: 0 auto; | |
padding:10px; | |
color:#FFFFFF; | |
margin-top:20px; | |
border-radius: 15px; | |
} | |
.content { text-align:left;padding:10px;height:300px;margin-top:20px;} | |
.hidden { display:none; } | |
</style> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" type="text/javascript"></script> | |
<script src="Silverlight.js" type="text/javascript"></script> | |
<script src="Silverlight.supportedUserAgent.js" type="text/javascript"></script> | |
<!-- Silverlight error script --> | |
<script type="text/javascript"> | |
function onSilverlightError(sender, args) | |
{ | |
// A work around for upgrade issues | |
if (args.ErrorCode.toString().indexOf("8001") > -1) | |
{ | |
showState("#upgrade-start"); | |
return; | |
} | |
if (args.ErrorCode.toString().indexOf("8002") > -1) { | |
showState("#restart-pending"); | |
return; | |
} | |
if (Silverlight.IsVersionAvailableOnError(sender, args)) | |
{ | |
var appSource = ""; | |
if (sender != null && sender != 0) { | |
appSource = sender.getHost().Source; | |
} | |
var errorType = args.ErrorType; | |
var iErrorCode = args.ErrorCode; | |
var errMsg = "Unhandled Error in Silverlight Application " + appSource + "\n"; | |
errMsg += "Code: " + iErrorCode + " \n"; | |
errMsg += "Category: " + errorType + " \n"; | |
errMsg += "Message: " + args.ErrorMessage + " \n"; | |
if (errorType == "ParserError") { | |
errMsg += "File: " + args.xamlFile + " \n"; | |
errMsg += "Line: " + args.lineNumber + " \n"; | |
errMsg += "Position: " + args.charPosition + " \n"; | |
} | |
else if (errorType == "RuntimeError") { | |
if (args.lineNumber != 0) { | |
errMsg += "Line: " + args.lineNumber + " \n"; | |
errMsg += "Position: " + args.charPosition + " \n"; | |
} | |
errMsg += "MethodName: " + args.methodName + " \n"; | |
} | |
throw new Error(errMsg); | |
} | |
} | |
</script> | |
<script type="text/javascript"> | |
$(document).ready(function() | |
{ | |
if (Silverlight.supportedUserAgent()) | |
{ | |
$("#install-start a").click(function() | |
{ | |
$("#install-start").toggle(); | |
$("#install-complete").toggle(); | |
window.location = "http://go2.microsoft.com/fwlink/?linkid=124807"; | |
}); | |
$("#upgrade-start a").click(function() | |
{ | |
$("#upgrade-start").toggle(); | |
$("#upgrade-complete").toggle(); | |
window.location = "http://go2.microsoft.com/fwlink/?linkid=124807"; | |
}); | |
$("#restart-pending a").click(function() | |
{ | |
$("#install-container").hide(); | |
$("#silverlightControlHost").show(); | |
}); | |
} | |
else | |
{ | |
showState("#not-supported"); | |
} | |
}); | |
function onSilverlightLoad(sender) | |
{ | |
Silverlight.IsVersionAvailableOnLoad(sender); | |
} | |
Silverlight.onRestartRequired = function() | |
{ | |
if (Silverlight.supportedUserAgent()) | |
showState("#restart-pending"); | |
}; | |
Silverlight.onUpgradeRequired = function() | |
{ | |
if (Silverlight.supportedUserAgent()) | |
showState("#upgrade-start"); | |
}; | |
Silverlight.onInstallRequired = function() | |
{ | |
if (Silverlight.supportedUserAgent()) | |
showState("#install-start"); | |
}; | |
function showState(id) | |
{ | |
$("#silverlightControlHost").hide(); | |
$("#install-container").show(); | |
$(id).toggle(); | |
} | |
</script> | |
</head> | |
<body> | |
<div id="install-container" class="hidden"> | |
<div class="content"> | |
<!-- No silverlight installed --> | |
<div id="install-start" class="hidden"> | |
<h1>You need to install Silverlight</h1> | |
<a href="javascript:;">Click here to install it.</a> | |
</div> | |
<!-- Install pending or completed --> | |
<div id="install-complete" class="hidden"> | |
<h1>Installing Silverlight...</h1> | |
Please restart your browser once the installation is complete. | |
</div> | |
<!-- Upgrade starting --> | |
<div id="upgrade-start" class="hidden"> | |
<h1>You need to upgrade Silverlight</h1> | |
You to upgrade the Silverlight plugin before you continue. | |
<a href="javascript:;">Click here to upgrade it.</a> | |
</div> | |
<!-- Upgrade pending or complete --> | |
<div id="upgrade-complete" class="hidden"> | |
<h1>Upgrading Silverlight...</h1> | |
Please restart your browser once the upgrade is complete. | |
</div> | |
<!-- Restart required --> | |
<div id="restart-pending" class="hidden"> | |
<h1>Please restart your browser before continuing.</h1> | |
If you have already restarted your browser, <a href="javascript:;">click here</a> to continue. | |
</div> | |
<!-- Not supported --> | |
<div id="not-supported" class="hidden"> | |
<h1>Sorry, your browser does not yet support Microsoft Silverlight.</h1> | |
Silverlight is currently supported on the following browsers: | |
<ul> | |
<li>Microsoft Internet Explorer</li> | |
<li>Mozilla Firefox 3+ (Windows and Mac OS X)</li> | |
<li>Google Chrome (Windows)</li> | |
<li>Safari (Mac OS X)</li> | |
</ul> | |
Please use one of the browsers above to be to enable the enhanced editor. | |
</div> | |
</div> | |
</div> | |
<div id="silverlightControlHost" style="height:100%;"> | |
<object data="data:application/x-silverlight," type="application/x-silverlight" width="100%" height="100%"> | |
<param name="source" value="Silverlightsniffing.xap"/> | |
<param name="background" value="white" /> | |
<param name="minRuntimeVersion" value="4.0" /> | |
<param name="autoUpgrade" value="false" /> | |
<param name="onerror" value="onSilverlightError" /> | |
<param name="onload" value="onSilverlightLoad" /> | |
</object> | |
<iframe style='visibility:hidden;height:0;width:0;border:0px'></iframe> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment