Thursday, September 11, 2014

How To Display Current Time on Page using Javascript

Here is the JavaScript function which will get current time in Military format.

<script type="text/javascript">
function startTime()
{
var today=new Date();
var h=today.getHours();
var m=today.getMinutes();
var s=today.getSeconds();
// add a zero in front of numbers<10
m=checkTime(m);
s=checkTime(s);
document.getElementById('Showtime').innerHTML=h+":"+m+":"+s;
t=setTimeout(function(){startTime()},500);
}

function checkTime(i)
{
if (i<10)
{
i="0" + i;
}
return i;
}
</script>

Sunday, August 24, 2014

How To Copy Content From a protected Webpage

Sometimes it is very annoying when you want to copy any news or article or anything that you want to save and when you right clicks on it but it shows “Right click disabled”. Here are some tips that can be useful on different browsers

For Mozilla FireFox:

Step 1: Open any website that have blocked your right click.
Step 2: Go to Tools>Options>Content
Step 3: Uncheck the box “Enable JavaScript”
Step 4: Click OK

For Internet Explorer:

Step 1: Open the site.
Step 2: Go to Tools>Internet options>Security
Step 3: Now Click on Custom Level
Step 4: Now find Scripting Section it will be around the end.
Step 5: Now disable Active Scripting.This will disable JavaScript and vbscript in your browser.
Step 6:Click on OK.

For Google Chrome:

Step 1: Open the site.
Step 2: Go to settings.
Step 3: Expand Show Advance settings, On Privacy tab.Click on Content Settings.
Step 4: Disable java script and open the website.

Tuesday, August 12, 2014

How to Parse datetime in multiple formats

Here is how we can parse different date formats get validated using one function.

In VB.NET

'''Validate method for Date format
  Private Function validateDate(ByVal strDate As String, ByVal strColumnName As String) As String
        Dim strError As String = ""
        Dim provider As CultureInfo = CultureInfo.GetCultureInfo("en-us")
        Dim formatStrings As String() = {"MM/dd/yyyy", "yyyy-MM-dd", "d"}
        Dim dateValue As DateTime
        Try
            If DateTime.TryParseExact(strDate, formatStrings, provider, DateTimeStyles.None, dateValue) Then
                strError = "Success"
            Else
                strError = "Failed"
            End If
        Catch ex As Exception

        End Try
        Return strError
    End Function

In C#

///Validate method for Date format
private string validateDate(string strDate, string strColumnName)
{
    string strError = "";
    CultureInfo provider = CultureInfo.GetCultureInfo("en-us");
    string[] formatStrings = {
        "MM/dd/yyyy",
        "yyyy-MM-dd",
        "d"
    };
    DateTime dateValue = default(DateTime);
    try {
        if (DateTime.TryParseExact(strDate, formatStrings, provider, DateTimeStyles.None, out dateValue)) {
            strError = "Success";
        } else {
            strError = "Failed";
        }

    } catch (Exception ex) {
    }
    return strError;
}

Add as many as formatters to the formatStrings array and use this funtion. Happy Coding ☺☻

Thursday, August 07, 2014

How to enable browser compatibility mode for your website

After every browser major release there will be something's which always mess up. Can’t say its always but it has happened so far :- )

So you might asked to force to the stable version of the browser to make sure your web application renders well in the browser. Here are some things we can add to existing page to make sure it works in the compatible mode by forcing the version we would like to render.

Method 1: If its at page level.

<head>
<!-- Mimic Internet Explorer 9 -->
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE9" >
<title>My webpage</title>
</head>



Method2: You can do the same globally in web.config by adding code like below


<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<httpProtocol>
<customHeaders>
<clear />
<add name="X-UA-Compatible" value="IE=EmulateIE9" />
</customHeaders>
</httpProtocol>
</system.webServer>
</configuration>


The value attribute is used to set the default render engine to render page. If you are looking for IE8 compatibility use the following code


<add name="X-UA-Compatible" value="IE=EmulateIE8" />


we can also use this tag


<add name="X-UA-Compatible" value="IE=Edge" />


IE=edge indicates that IE should always use its latest rendering engine to render the page. This should ensure the page is rendered consistently with other browsers and in a standards-compliant manner


The following is the documentation that I've used to try understand how IE decides to actually trigger the compatibility mode.

http://msdn.microsoft.com/en-us/library/ff406036%28v=VS.85%29.aspx

http://blogs.msdn.com/b/ie/archive/2009/02/16/just-the-facts-recap-of-compatibility-view.aspx

Wednesday, July 16, 2014

Thank you Google!

I didn’t know Google does this. I was just shocked to realize this to what I got to see on my birthday! Thanks Google you rock. This is the one of the most intuitive thing you have ever done to keep us happy.

 

google doogle -nagasai