Monday, August 22, 2011

Print div content in using Javsscript??

Below code used to print div content here we have to write printable content in "printDiv" 

    <form id="Form1" method="post" runat="server">
 <div id="printDiv">
  Printable content
 </div>
 <input type="button" value="Print" onclick="JavaScript:printPartOfPage('printDiv');">

<script type="text/javascript">
<!--
function printPartOfPage(elementId)
{
 var printContent = document.getElementById(elementId);
 var windowUrl = 'about:blank';
 var uniqueName = new Date();
 var windowName = 'Print' + uniqueName.getTime();
 var printWindow = window.open(windowUrl, windowName, 'left=50000,top=50000,width=0,height=0');

 printWindow.document.write(printContent.innerHTML);
 printWindow.document.close();
 printWindow.focus();
 printWindow.print();
 printWindow.close();
}
// -->
</script>

</form>


Njoy coding......

Sunday, August 14, 2011

Playing You tube video on own site??

A jQuery plugin to hook into the YouTube Chromeless Video API.
Sample Usage:
<a href="http://www.youtube.com/watch?v=sxUjB3Q04rQ&quot; class="video-link">Bolt Arms - Around the World</a>

$(document).ready(function() {
  $('a.video-link').ytchromeless();
});


Requirements:
- jQuery: http://jquery.com/
- SWFObject: http://code.google.com/p/swfobject/
- YouTube Chromeless Video Plugin: http://github.com/davist11/YouTube-Chromeless


Options:
- videoWidth : '640'
- videoHeight : '360'
- videoIdBase : 'ytplayer'
- params : { allowScriptAccess: 'always', wmode: 'transparent' }
Njoy Coding.....:)

Tuesday, August 2, 2011

cookies with jquery(set,get and delete cookies)........??

I can easily manage cookies information by using  jquery cookie plugin.

Download jquery cookie plugin here http://plugins.jquery.com/project/Cookie

Here I was share simple script to handle jquery cookies:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>

    <script src="js/jquery-1.4.4.min.js" type="text/javascript"></script>

    <script src="js/jquery.cookie.js" type="text/javascript"></script>
    <script type="text/javascript" language="javascript">
    function setCookie(name,value,days) {
        if (days) {
            var date = new Date();
            date.setTime(date.getTime()+(days*24*60*60*1000));
            var expires = "; expires="+date.toGMTString();
        }
        else var expires = "";
        document.cookie = name+"="+value+expires+"; path=/";
    }

    function getCookie(name) {
        var nameEQ = name + "=";
        var ca = document.cookie.split(';');
        for(var i=0;i < ca.length;i++) {
            var c = ca[i];
            while (c.charAt(0)==' ') c = c.substring(1,c.length);
            if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
        }
        return null;
    }

    function deleteCookie(name) {
        setCookie(name,"",-1);
    } 
   
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <input id="Button1" type="button" onclick="setCookie('myCookie', 'myValue', 1);" value="SetCookies" />
        <input id="Button2" type="button" onclick="alert(getCookie('myCookie'));" value="GetCookies" />
        <input id="Button3" type="button" onclick="deleteCookie('myCookie');" value="DeleteCookiess" />
    </div>
    </form>
</body>
</html>

In above code setCookie() used for setting cookies, getCookie() function used for get cookies value and deleteCookie() used for delete cookies information.

Njoy coding.....:)