<html>
<head>
<title></title>
<style type="text/css">
.gray
{
color: Gray;
}
.black
{
color: Black;
}
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script language="javascript" type="text/javascript">
$(function () {
$("#txtDate").val("dd/mm/yyyy").addClass("gray");
$("#txtDate").focus(function () {
if ($("#txtDate").val() == "dd/mm/yyyy") {
$("#txtDate").val("").addClass("black").removeClass("gray");
}
});
$("#txtDate").focusout(function () {
if ($("#txtDate").val() == "") {
$("#txtDate").val("dd/mm/yyyy").addClass("gray").removeClass("black");
}
});
});
</script>
</head>
<body>
<input id="txtDate" type="text" />
</body>
</html>
Friday, March 23, 2012
Thursday, March 22, 2012
Convert a file to a byte array
///
/// Function to get byte array from a file
///
/// File name to get byte array
///Byte Array
public byte[] FileToByteArray(string fileName)
{
byte[] buffer = null;
try
{
// Open file for reading
System.IO.FileStream fileStream = new System.IO.FileStream(fileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
// attach filestream to binary reader
System.IO.BinaryReader binaryReader = new System.IO.BinaryReader(fileStream);
// get total byte length of the file
long totalBytes = new System.IO.FileInfo(fileName).Length;
// read entire file into buffer
buffer = binaryReader.ReadBytes((Int32)totalBytes);
// close file reader
fileStream.Close();
fileStream.Dispose();
binaryReader.Close();
}
catch (Exception exception)
{
// Error
Console.WriteLine("Exception caught in process: {0}", exception.ToString());
}
return buffer;
}
/// Function to get byte array from a file
///
/// File name to get byte array
///
public byte[] FileToByteArray(string fileName)
{
byte[] buffer = null;
try
{
// Open file for reading
System.IO.FileStream fileStream = new System.IO.FileStream(fileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
// attach filestream to binary reader
System.IO.BinaryReader binaryReader = new System.IO.BinaryReader(fileStream);
// get total byte length of the file
long totalBytes = new System.IO.FileInfo(fileName).Length;
// read entire file into buffer
buffer = binaryReader.ReadBytes((Int32)totalBytes);
// close file reader
fileStream.Close();
fileStream.Dispose();
binaryReader.Close();
}
catch (Exception exception)
{
// Error
Console.WriteLine("Exception caught in process: {0}", exception.ToString());
}
return buffer;
}
JavaScript Browser Detection
Sometimes it can be useful to detect the visitor's browser, and then serve the appropriate information.
The Navigator object contains information about the visitor's browser name, version, and more.
Sample Code :
<html>
<head>
<script language="javascript" type="text/javascript">
function browserDetect() {
var browserType;
if(/chrome/.test( navigator.userAgent.toLowerCase() )){
browserType="chrome";
}
else if(/webkit/.test( navigator.userAgent.toLowerCase() )){
browserType="safari";
}
else if(/opera/.test( navigator.userAgent.toLowerCase() )){
browserType="opera";
}
else if(/msie/.test( navigator.userAgent.toLowerCase() )){
//browserType="msie";
if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) { //test for MSIE x.x;
var ieversion = new Number(RegExp.$1) // capture x.x portion and store as a number
browserType="msie " + ieversion;
}
}
else if(/mozilla/.test( navigator.userAgent.toLowerCase() )){
browserType="mozilla";
}
else
{
browserType="none of these - chrome,safari,opera,msie,mozilla";
}
alert(browserType);
}
</script>
</head>
<body>
<a href="javascript:browserDetect();">Detect Browser</a>
</body>
</html>
The Navigator object contains information about the visitor's browser name, version, and more.
Sample Code :
<html>
<head>
<script language="javascript" type="text/javascript">
function browserDetect() {
var browserType;
if(/chrome/.test( navigator.userAgent.toLowerCase() )){
browserType="chrome";
}
else if(/webkit/.test( navigator.userAgent.toLowerCase() )){
browserType="safari";
}
else if(/opera/.test( navigator.userAgent.toLowerCase() )){
browserType="opera";
}
else if(/msie/.test( navigator.userAgent.toLowerCase() )){
//browserType="msie";
if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) { //test for MSIE x.x;
var ieversion = new Number(RegExp.$1) // capture x.x portion and store as a number
browserType="msie " + ieversion;
}
}
else if(/mozilla/.test( navigator.userAgent.toLowerCase() )){
browserType="mozilla";
}
else
{
browserType="none of these - chrome,safari,opera,msie,mozilla";
}
alert(browserType);
}
</script>
</head>
<body>
<a href="javascript:browserDetect();">Detect Browser</a>
</body>
</html>
Subscribe to:
Posts (Atom)