<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Php Development &#187; javascript</title>
	<atom:link href="http://www.maheshchari.com/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.maheshchari.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Sun, 23 May 2010 05:10:57 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Serve your PHP file as JavaScript file</title>
		<link>http://www.maheshchari.com/serve-your-php-file-as-javascript-file/</link>
		<comments>http://www.maheshchari.com/serve-your-php-file-as-javascript-file/#comments</comments>
		<pubDate>Wed, 24 Mar 2010 17:23:17 +0000</pubDate>
		<dc:creator>mahesh chari</dc:creator>
				<category><![CDATA[PHP/mysql]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.maheshchari.com/?p=523</guid>
		<description><![CDATA[Serve Your PHP script as JavaScript file.
Some times we need to serve user based JavaScript files, for example

passing your php variables to JavaScript on client side of browser.
protecting JavaScript variables.
setting browser cache manually for JavaScript files.
loading user based java script files.
for easy versification of your JavaScript files.

Download Demo
Suppose your php-javascript file &#8220;my-phpjavascript.js.php&#8221; ,now you can [...]]]></description>
			<content:encoded><![CDATA[<h1>Serve Your PHP script as JavaScript file.</h1>
<p>Some times we need to serve user based JavaScript files, for example</p>
<ul>
<li>passing your php variables to JavaScript on client side of browser.</li>
<li>protecting JavaScript variables.</li>
<li>setting browser cache manually for JavaScript files.</li>
<li>loading user based java script files.</li>
<li>for easy versification of your JavaScript files.</li>
</ul>
<h3><a href='http://www.maheshchari.com/wp-content/uploads/2010/03/wp.zip'>Download Demo</a></h3>
<p>Suppose your php-javascript file &#8220;<b>my-phpjavascript.js.php</b>&#8221; ,now you can add this file as below example.</p>
<h3>Client HTML code</h3>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;html&gt;
&lt;head&gt;
&lt;script  type=&quot;text/javascript&quot; src=&quot;my-phpjavascript.js.php&quot;&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;script&gt;
alert(site_name);
&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></div></div>

<h3>my-phpjavascript.js.php code</h3>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> 
<span style="color: #666666; font-style: italic;">// this is PHP variable</span>
<span style="color: #000088;">$sitename</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;My PHP development blog.&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
//this is javascript variable 
var site_name=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$sitename</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;;</pre></div></div>

<p>some browsers don&#8217;t recognize this php file as javascript ,so to make all browser compatibility we have to send javascript headers to browser ,we can do that by adding a few line of code at starting of php script. </p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;Content-Type: text/javascript; charset=utf-8&quot;</span>  <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Remember to preview this code you must installed PHP</p>
<h3><a href='http://www.maheshchari.com/wp-content/uploads/2010/03/wp.zip'>Download Demo</a></h3>
<img src="http://www.maheshchari.com/?ak_action=api_record_view&id=523&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.maheshchari.com/serve-your-php-file-as-javascript-file/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>prevent iframe ,frame theft</title>
		<link>http://www.maheshchari.com/prevent-iframe-frame-theft/</link>
		<comments>http://www.maheshchari.com/prevent-iframe-frame-theft/#comments</comments>
		<pubDate>Sun, 31 Jan 2010 09:56:17 +0000</pubDate>
		<dc:creator>mahesh chari</dc:creator>
				<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.maheshchari.com/?p=404</guid>
		<description><![CDATA[How to stop iframe, frame thefts of our site resources.
Sites like Google Image search , goodphptutorials.com and phpcamp.net displays the  website under the IFRAME .No one want their site to  be displayed it under the IFRAME, FRAMES. If you want to protect your site to  be displayed under the IFRAME,FRAMES then just [...]]]></description>
			<content:encoded><![CDATA[<h1>How to stop iframe, frame thefts of our site resources.</h1>
<p>Sites like Google Image search , goodphptutorials.com and phpcamp.net displays the  website under the IFRAME .No one want their site to  be displayed it under the IFRAME, FRAMES. If you want to protect your site to  be displayed under the IFRAME,FRAMES then just copy and paste below javascript code after body tag.</p>
<p>&nbsp;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>window.<span style="color: #660066;">top</span> <span style="color: #339933;">!==</span> window.<span style="color: #660066;">self</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
document.<span style="color: #000066; font-weight: bold;">write</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">;</span>
window.<span style="color: #660066;">top</span>.<span style="color: #660066;">location</span> <span style="color: #339933;">=</span> window.<span style="color: #660066;">self</span>.<span style="color: #660066;">location</span><span style="color: #339933;">;</span> setTimeout<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>document.<span style="color: #660066;">body</span>.<span style="color: #660066;">innerHTML</span><span style="color: #339933;">=</span><span style="color: #3366CC;">''</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
window.<span style="color: #660066;">self</span>.<span style="color: #000066;">onload</span><span style="color: #339933;">=</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>evt<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
document.<span style="color: #660066;">body</span>.<span style="color: #660066;">innerHTML</span><span style="color: #339933;">=</span><span style="color: #3366CC;">''</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Here we use simple logic that we check our page document window is main window or not. if our document isn&#8217;t in main window it might be in iframe or frame. then we switch the location of main window to our existing document locations.  Before doing this redirection we make the document empty, because the imposter can break this code before loading . </p>
<img src="http://www.maheshchari.com/?ak_action=api_record_view&id=404&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.maheshchari.com/prevent-iframe-frame-theft/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery ajaxstart ajaxstop</title>
		<link>http://www.maheshchari.com/jquery-ajaxstart-ajaxstop/</link>
		<comments>http://www.maheshchari.com/jquery-ajaxstart-ajaxstop/#comments</comments>
		<pubDate>Sat, 09 Jan 2010 11:14:48 +0000</pubDate>
		<dc:creator>mahesh chari</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://www.maheshchari.com/?p=393</guid>
		<description><![CDATA[Displaying Ajax started element using JQuery ajaxstart,ajaxstop
jQuery is most famous javascript library compared to its concurrents. One of importent functionality in jQuery is its Ajax handling. It has very flexible methods for Ajax.We seen how to handle the Ajax Errors in my previous Article.Here we concentrate on jQuery ajaxstart,ajaxstop default methods to handle globally. 
Present [...]]]></description>
			<content:encoded><![CDATA[<h2>Displaying Ajax started element using JQuery ajaxstart,ajaxstop</h2>
<p>jQuery is most famous javascript library compared to its concurrents. One of importent functionality in jQuery is its Ajax handling. It has very flexible methods for Ajax.We seen how to handle the Ajax Errors in my previous Article.Here we concentrate on jQuery ajaxstart,ajaxstop default methods to handle globally. </p>
<p>Present it is very common to use ajax for every functionality,while querying externel resources with ajax we have to show the end user there is something happening behind the page.Some novice users don&#8217;t know about this functionality. So we must intimate the end user we are working on back end. Some times Ajax calls takes more time to respond with some reason. in that case most users confused about it may be stopped working . so here we take one example and tutorial.</p>
<h3>ajaxStart</h3>
<p>This method is called globally by jQuery while before starting any ajax call starts.</p>
<h3>ajaxstop</h3>
<p>This method called after stopping the Ajax stopped successfully or Ajax call cancelled.</p>
<p>These methods called on $.getJSON,$.get,$.post,$().load,$.getScript function.</p>
<h3>Example</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="javacript" style="font-family:monospace;">jQuery().ready(function(){ //Dom ready 
$('#loadimg').ajaxStart(function(){$(this).show();});//this method for ajax start		
$('#loadimg').ajaxStop(function(){$(this).hide();});//this method for ajax stop
$('#loadjson').click(function(){
$.getJSON('ajax.js',function(d){alert(d.name);});//$.getJSON method
});
$('#loadelement').click(function(){$(this).load('loadsnippet.html')});//load method
});</pre></td></tr></table></div>

<p><a href="http://www.maheshchari.com">Try more examples</a></p>
<p>&nbsp;</p>
<p><a href='http://www.maheshchari.com/wp-content/uploads/2010/01/ajaxstart.zip'>Demo Download</a></p>
<img src="http://www.maheshchari.com/?ak_action=api_record_view&id=393&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.maheshchari.com/jquery-ajaxstart-ajaxstop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>hide javascript code from non javascript browser</title>
		<link>http://www.maheshchari.com/hide-javascript-code-from-non-javascript-browser/</link>
		<comments>http://www.maheshchari.com/hide-javascript-code-from-non-javascript-browser/#comments</comments>
		<pubDate>Wed, 26 Aug 2009 03:14:42 +0000</pubDate>
		<dc:creator>mahesh chari</dc:creator>
				<category><![CDATA[Html]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[browser]]></category>

		<guid isPermaLink="false">http://www.maheshchari.com/?p=368</guid>
		<description><![CDATA[hide JavaScript code from non-JavaScript  browsers
Here we learn how to hide the javascript code from non javascript browsers , javascript disabled browsers and mobile browsers .Non javascript browsers renders the javascript code as generel text without exucuting the code. So we must aware how to hide the javascript from these browsers.
&#160; 

1
2
3
4
5
&#60;script type=&#34;text/javascript&#34;&#62;
&#60;!--
alert&#40;&#34;This alert [...]]]></description>
			<content:encoded><![CDATA[<h1>hide JavaScript code from non-JavaScript  browsers</h1>
<p>Here we learn how to hide the javascript code from non javascript browsers , javascript disabled browsers and mobile browsers .Non javascript browsers renders the javascript code as generel text without exucuting the code. So we must aware how to hide the javascript from these browsers.</p>
<p>&nbsp; </p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;!--</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;This alert box is hidden from non javascript browsers.!!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">//--&gt;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<img src="http://www.maheshchari.com/?ak_action=api_record_view&id=368&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.maheshchari.com/hide-javascript-code-from-non-javascript-browser/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>check browser java enabled</title>
		<link>http://www.maheshchari.com/check-browser-java-enabled/</link>
		<comments>http://www.maheshchari.com/check-browser-java-enabled/#comments</comments>
		<pubDate>Tue, 28 Jul 2009 11:48:33 +0000</pubDate>
		<dc:creator>mahesh chari</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[browser]]></category>

		<guid isPermaLink="false">http://www.maheshchari.com/?p=338</guid>
		<description><![CDATA[Check Browser Java application enabled

Java  is a high-level, third generation  programming language, like C and many  others.Java allows you to play online games, chat with people around the  world, calculate your mortgage interest, and view images in 3D, just to  name a few. It&#8217;s also integral to the intranet applications [...]]]></description>
			<content:encoded><![CDATA[<h1>Check Browser Java application enabled<br />
</h1>
<p><strong>Java</strong>  is a high-level, third generation  programming language, like C and many  others.<strong>Java</strong> allows you to play online games, chat with people around the  world, calculate your mortgage interest, and view images in 3D, just to  name a few. It&#8217;s also integral to the intranet applications and other  e-business solutions that are the foundation of corporate computing.<br />
  With some reasons the web browser don&rsquo;t support <strong>Javas</strong> ,like user intentially disables,some browsers don&rsquo;t support.Then we must check the whether user&rsquo;s web browser has<strong> Java</strong> enabled.Here we discuss how to handle <strong>non Java browser</strong>. </p>
<h3>We show normal warning message with javascript. </h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script<span style="color: #339933;">&gt;</span>
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>navigator.<span style="color: #660066;">javaEnabled</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Java Enabled.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #006600; font-style: italic;">//we do our normal action</span>
<span style="color: #009900;">&#125;</span><span style="color: #000066; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Java Disabled.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #006600; font-style: italic;">//we warn the user to download or other </span>
<span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<h3>We redirect the user to seperate UI or seperate <strong>sub domain</strong> that handles for non <strong>java browser</strong>.</h3>
<p>&nbsp; </p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script<span style="color: #339933;">&gt;</span>
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>navigator.<span style="color: #660066;">javaEnabled</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Java Enabled.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #006600; font-style: italic;">//we do our normal action</span>
<span style="color: #009900;">&#125;</span><span style="color: #000066; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
document.<span style="color: #660066;">location</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;nonjava-html-page.html&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<img src="http://www.maheshchari.com/?ak_action=api_record_view&id=338&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.maheshchari.com/check-browser-java-enabled/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>check javascript disabled</title>
		<link>http://www.maheshchari.com/check-javascript-disabled/</link>
		<comments>http://www.maheshchari.com/check-javascript-disabled/#comments</comments>
		<pubDate>Tue, 21 Jul 2009 03:09:42 +0000</pubDate>
		<dc:creator>mahesh chari</dc:creator>
				<category><![CDATA[Html]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[browser]]></category>

		<guid isPermaLink="false">http://www.maheshchari.com/?p=326</guid>
		<description><![CDATA[Check Browser Javascript enabled
JavaScript is a small, lightweight, object-oriented, cross-platform scripting language.JavaScript is used in millions of Web pages to add functionality, validate forms, detect browsers, and much more.With some reasons the web browser don&#8217;t support Javascript ,like user intentially disables,some  mobile browsers  version don&#8217;t support.Then it must we check the whether user&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<h1>Check Browser Javascript enabled</h1>
<p><strong>JavaScript</strong> is a small, lightweight, object-oriented, cross-platform scripting language.JavaScript is used in millions of Web pages to add functionality, validate forms, detect browsers, and much more.With some reasons the web browser don&#8217;t support <strong>Javascript</strong> ,like user<strong> intentially disables</strong>,some  <strong>mobile browsers</strong>  version don&#8217;t support.Then it must we check the whether user&#8217;s web browser has Javascript enabled.Here we discuss how to <strong>handle non Javascript browser</strong>.</p>
<p>We show a alert ,<strong>warning message</strong> if user browser don&#8217;t hav Javascript enabled.using <strong>&lt;noscript&gt;</strong> HTML tag. just add bellow code to any where in the <strong>body </strong>section.<strong>&lt;noscript&gt;</strong> element will be rendered by those <strong>Javascript disabled</strong> browsers. </p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;noscript&gt;&lt;font face=arial&gt;JavaScript must be enabled in order for you to use maheshchari.com in standard view. However, it seems JavaScript is either disabled or not supported by your browser. To use standard view, enable JavaScript by changing your browser options, then &lt;a href=&quot;&quot;&gt;try again&lt;/a&gt;. &lt;/font&gt;&lt;/noscript&gt;</pre></td></tr></table></div>

<p>We show a alert ,warning message with Javascript itself if user browser <strong>doesn&#8217;t support &lt;noscript&gt;</strong> HTML tag.below example code demonstrates.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;div id=&quot;nojs&quot;&gt;&lt;font face=arial&gt;JavaScript must be enabled in order for you to use maheshchari.com in standard view. However, it seems JavaScript is either disabled or not supported by your browser. To use standard view, enable JavaScript by changing your browser options, then &lt;a href=&quot;&quot;&gt;try again&lt;/a&gt;.&lt;/font&gt;&lt;/div&gt;
&lt;script&gt;
//if script enabled warning message hidden.
document.getElementById('nojs').style.display=&quot;none&quot;;
&lt;/script&gt;</pre></td></tr></table></div>

<p>&nbsp;</p>
<p>We create <strong>seperate UI</strong> or <strong>seperate web site</strong> for those <strong>Javascript disabled</strong> browsers. below example redirects the user automatically if <strong>Javascript disabled.</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;html&gt;
&lt;head&gt;
&lt;noscript&gt;
&lt;meta http-equiv=&quot;refresh&quot; content=&quot;0;URL=http://mobile.maheshchari.com&quot; /&gt;
&lt;/noscript&gt;
&lt;/head&gt;
&lt;body&gt;&lt;/body&gt;
&lt;/html&gt;</pre></td></tr></table></div>

<p>&nbsp; </p>
<img src="http://www.maheshchari.com/?ak_action=api_record_view&id=326&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.maheshchari.com/check-javascript-disabled/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>check cookie enabled javascript php</title>
		<link>http://www.maheshchari.com/check-cookie-enabled-javascript-php/</link>
		<comments>http://www.maheshchari.com/check-cookie-enabled-javascript-php/#comments</comments>
		<pubDate>Mon, 20 Jul 2009 02:49:18 +0000</pubDate>
		<dc:creator>mahesh chari</dc:creator>
				<category><![CDATA[PHP/mysql]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[browser]]></category>

		<guid isPermaLink="false">http://www.maheshchari.com/?p=323</guid>
		<description><![CDATA[How to check browser cookie enabled with php javascript
Cookies are typically used by web servers to perform functions such as tracking your visits to websites, enabling you to log in to sites, and storing your shopping cart. Cookies can be used to interaction between Javascript and Server Side  Scripts like PHP.Cookies also used to transfer [...]]]></description>
			<content:encoded><![CDATA[<h1>How to check browser cookie enabled with php javascript</h1>
<p>Cookies are typically used by web servers to perform functions such as tracking your visits to websites, enabling you to log in to sites, and storing your shopping cart. Cookies can be used to interaction between Javascript and Server Side  Scripts like PHP.Cookies also used to transfer small amount of data between one page to other pages via HTTP headers .If user disables this cookies or user&#8217;s browser won&#8217;t support the interaction between JS and PHP fails.So we must ensure user must enable these Cookies.</p>
<p>In this article,we check the user&#8217;s browser Cookie enabled or not.This can be achieved by both client side Javascript and Server Side Script.</p>
<h3>Checking with Javascript</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>navigator.<span style="color: #660066;">cookieEnabled</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;You need to enable cookies for this site to load properly!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h3>Checking with PHP</h3>
<p>If user disables Javascript we fail to check the Cookie enabled or not.So we check on the server side also.below PHP snippet check the Cookie enabled or not.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> check_cookie<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">setcookie</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;test&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;test&quot;</span><span style="color: #339933;">,</span> <span style="color: #990000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">360</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">@</span><span style="color: #000088;">$_COOKIE</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'test'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<img src="http://www.maheshchari.com/?ak_action=api_record_view&id=323&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.maheshchari.com/check-cookie-enabled-javascript-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jquery ajax error handling</title>
		<link>http://www.maheshchari.com/jquery-ajax-error-handling/</link>
		<comments>http://www.maheshchari.com/jquery-ajax-error-handling/#comments</comments>
		<pubDate>Thu, 09 Jul 2009 13:05:19 +0000</pubDate>
		<dc:creator>mahesh chari</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[ajax]]></category>

		<guid isPermaLink="false">http://www.maheshchari.com/?p=244</guid>
		<description><![CDATA[How to handle ajax errors using jQuery ? 
jQuery is the most awesome javascript library that made easy for asynchronous ajax calls.it has global ajax function and some pre defined ajax functions like $.get, $.post, load .etc. but we don&#8217;t find any error messages by default with this library. we can see the errors with [...]]]></description>
			<content:encoded><![CDATA[<h1>How to handle ajax errors using jQuery ? </h1>
<p><strong>jQuery</strong> is the most awesome javascript <strong>library</strong> that made easy for <strong>asynchronous ajax </strong>calls.it has global <strong>ajax</strong> function and some pre defined ajax functions like <strong>$.get</strong>, <strong>$.post</strong>,<strong> load</strong> .etc. but we don&#8217;t find any <strong>error messages</strong> by default with this library. we can see the errors with firefox&#8217;s addon <strong>firebug</strong> or with <strong>IE developer toolbar</strong>.So we manage most common ajax errors in our application with global <strong>ajaxSetup</strong> function which come with <strong>jQuery</strong> by default. We can set many options,to see available <strong>ajaxsetup</strong> options please check <a href="http://docs.jquery.com/Ajax/jQuery.ajax#toptions" target="_blank" rel="nofallow">here</a>. </p>
<p>most ajax errors we get errors are server response errors and some <strong>JSON</strong> parse errors. To know more about the <strong>HTTP</strong> errors details please check <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html" target="_blank" rel="nofallow">here</a>. To test this error handling just copy and paste it to your head section of HTML document. </p>
<h3>Javascript Code for setting global error handling. </h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	$.<span style="color: #660066;">ajaxSetup</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
		error<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>x<span style="color: #339933;">,</span>e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>x.<span style="color: #000066;">status</span><span style="color: #339933;">==</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'You are offline!!<span style="color: #000099; font-weight: bold;">\n</span> Please Check Your Network.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span><span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>x.<span style="color: #000066;">status</span><span style="color: #339933;">==</span><span style="color: #CC0000;">404</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Requested URL not found.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span><span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>x.<span style="color: #000066;">status</span><span style="color: #339933;">==</span><span style="color: #CC0000;">500</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Internel Server Error.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span><span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>e<span style="color: #339933;">==</span><span style="color: #3366CC;">'parsererror'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Error.<span style="color: #000099; font-weight: bold;">\n</span>Parsing JSON Request failed.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span><span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>e<span style="color: #339933;">==</span><span style="color: #3366CC;">'timeout'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Request Time out.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span><span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Unknow Error.<span style="color: #000099; font-weight: bold;">\n</span>'</span><span style="color: #339933;">+</span>x.<span style="color: #660066;">responseText</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>In the above example we handle following common error and show response text for other rare errors.</p>
<ul>
<li>0-xhr status ,is it initialized or not that means user is offline. </li>
<li>404-page not found </li>
<li>500-Internel Server error. </li>
<li>request timeout &#8211; jQuery custom error.</li>
<li> parseerror-jQuery custom error when parsing JSON data. </li>
<li>we just throw other errors with response error </li>
</ul>
<h2>Example1</h2>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">params<span style="color: #339933;">=</span><span style="color: #009900;">&#123;</span><span style="color: #000066;">name</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'mahesh'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
$.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span>url<span style="color: #339933;">,</span>params<span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span></pre></td></tr></table></div>

<p>In above example,jQuery automatically raises all available errors,except parse error. because we didn&#8217;t give any return type format. </p>
<h2>Example2</h2>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">params<span style="color: #339933;">=</span><span style="color: #009900;">&#123;</span><span style="color: #000066;">name</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'mahesh'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
$.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span>url<span style="color: #339933;">,</span>params<span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'json'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$.<span style="color: #660066;">getJSON</span><span style="color: #009900;">&#40;</span>url<span style="color: #339933;">,</span>params<span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>In above example,jQuery automatically raises all available errors,because we added return type format at end. $.getJSON automatically adds the return type of parameter to &#8220;JSON&#8221;</p>
<h3>Example3</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">params<span style="color: #339933;">=</span><span style="color: #009900;">&#123;</span><span style="color: #000066;">name</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'mahesh'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
$.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span>url<span style="color: #339933;">,</span>params<span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'xml'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>
In the above example 3 ,we gave xml type return parameter, here also jQuery automatically raises all errors even parse error also.</p>
<img src="http://www.maheshchari.com/?ak_action=api_record_view&id=244&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.maheshchari.com/jquery-ajax-error-handling/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>javascript bookmark</title>
		<link>http://www.maheshchari.com/javascript-bookmark/</link>
		<comments>http://www.maheshchari.com/javascript-bookmark/#comments</comments>
		<pubDate>Fri, 26 Jun 2009 21:28:12 +0000</pubDate>
		<dc:creator>mahesh chari</dc:creator>
				<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.maheshchari.com/?p=219</guid>
		<description><![CDATA[javascript add bookmark or add favorite function tutorial
A simple cross-browser bookmarking / add to favorites script that works in IE6+ ,FF2+,Opera 7+.Adding the &#34;bookmark           this page&#34; javascript below will help to encourage your site return visits. To add this link just copy paste a small [...]]]></description>
			<content:encoded><![CDATA[<h1>javascript add bookmark or add favorite function tutorial</h1>
<p>A simple cross-browser bookmarking / add to favorites script that works in<strong> IE6</strong>+ ,<strong>FF2</strong>+,<strong>Opera</strong> 7+.Adding the<strong> &quot;bookmark           this page&quot;</strong> <strong>javascript</strong> below will help to encourage your site return visits. To add this link just copy paste a small script at your link position.it will add only supported browsers. </p>
<h3>Download source code</h3>
<p><a href='http://www.maheshchari.com/wp-content/uploads/2009/06/bookmark.zip'>bookmark</a></p>
<h3>javascript code</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script <span style="color: #339933;">&gt;</span>
<span style="color: #003366; font-weight: bold;">function</span> bookmark<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
title <span style="color: #339933;">=</span>document.<span style="color: #660066;">title</span><span style="color: #339933;">;</span> 
url <span style="color: #339933;">=</span> document.<span style="color: #660066;">location</span>.<span style="color: #660066;">href</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>window.<span style="color: #660066;">sidebar</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">//firefox bookmark functionality</span>
window.<span style="color: #660066;">sidebar</span>.<span style="color: #660066;">addPanel</span><span style="color: #009900;">&#40;</span>title<span style="color: #339933;">,</span> url<span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> window.<span style="color: #660066;">external</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">//ie favorite functionality</span>
window.<span style="color: #660066;">external</span>.<span style="color: #660066;">AddFavorite</span><span style="color: #009900;">&#40;</span> url<span style="color: #339933;">,</span> title<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #009900;">&#125;</span><span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>window.<span style="color: #660066;">opera</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #006600; font-style: italic;">//opera virtual sidebar link</span>
a <span style="color: #339933;">=</span> document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;A&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
a.<span style="color: #660066;">rel</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;sidebar&quot;</span><span style="color: #339933;">;</span>
a.<span style="color: #660066;">target</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;_search&quot;</span><span style="color: #339933;">;</span>
a.<span style="color: #660066;">title</span> <span style="color: #339933;">=</span> title<span style="color: #339933;">;</span>
a.<span style="color: #660066;">href</span> <span style="color: #339933;">=</span> url<span style="color: #339933;">;</span>
a.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> bookmarklink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>window.<span style="color: #660066;">sidebar</span> <span style="color: #339933;">||</span> window.<span style="color: #660066;">external</span> <span style="color: #339933;">||</span> window.<span style="color: #660066;">opera</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">//we build link for only supported browsers</span>
document.<span style="color: #000066; font-weight: bold;">write</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;a href = &quot;javascript:bookmark()&quot;);&quot;&gt;Add to Favorites&lt;/a&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #009900;">&#125;</span> 
<span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<h3>html code   </h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;html&gt;
&lt;head&gt;
&lt;title&gt;javascript bookmarking for firefox/IE/Safari&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;script &gt;
bookmarklink();
&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></td></tr></table></div>

<h3>Download source code</h3>
<p><a href='http://www.maheshchari.com/wp-content/uploads/2009/06/bookmark.zip'>bookmark</a></p>
<img src="http://www.maheshchari.com/?ak_action=api_record_view&id=219&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.maheshchari.com/javascript-bookmark/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>javascript image rollover</title>
		<link>http://www.maheshchari.com/javascript-image-rollover/</link>
		<comments>http://www.maheshchari.com/javascript-image-rollover/#comments</comments>
		<pubDate>Tue, 23 Jun 2009 17:00:25 +0000</pubDate>
		<dc:creator>mahesh chari</dc:creator>
				<category><![CDATA[Html]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[image]]></category>

		<guid isPermaLink="false">http://www.maheshchari.com/?p=206</guid>
		<description><![CDATA[image rollover effect with javascript image object

we create a image object with new Image();
 set a source attribute to test1.jpg.
create onmouseover even function ,then set image object src to test2.jpg
create onmouseout event function,then set image object src to test1.jpg
to test click even we can see a small alert box.   

Download Sorce Code
image-rollover-javascript

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
&#60;html&#62;
&#60;head&#62;
&#60;title&#62;Image Roll [...]]]></description>
			<content:encoded><![CDATA[<h1>image rollover effect with javascript image object</h1>
<ul>
<li>we create a image object with new Image();</li>
<li> set a source attribute to test1.jpg.</li>
<li>create onmouseover even function ,then set image object src to test2.jpg</li>
<li>create onmouseout event function,then set image object src to test1.jpg</li>
<li>to test click even we can see a small alert box.   </li>
</ul>
<h3>Download Sorce Code</h3>
<p><a href='http://www.maheshchari.com/wp-content/uploads/2009/06/image-rollover-javascript.zip'>image-rollover-javascript</a></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Image Roll over&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div id=&quot;imagerolover&quot;&gt;&lt;/div&gt;
&lt;script&gt;
var myimage=new Image(); //create a image object
myimage.src=&quot;test1.jpg&quot;;//initially set test1.jpg as src attribute
//onmouseover set test2.jpg as src
myimage.onmouseover=function(){
this.src=&quot;test2.jpg&quot;;
}
//on mouseout set test1.jpg src again
myimage.onmouseout=function(){
this.src=&quot;test1.jpg&quot;;
}
//create click event 
myimage.onclick=function(){
alert('U clicked me');
}
//get imagerolover div element by id and append the image
document.getElementById('imagerolover').appendChild(myimage);
&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></td></tr></table></div>

<h3>Download Sorce Code</h3>
<p><a href='http://www.maheshchari.com/wp-content/uploads/2009/06/image-rollover-javascript.zip'>image-rollover-javascript</a></p>
<img src="http://www.maheshchari.com/?ak_action=api_record_view&id=206&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.maheshchari.com/javascript-image-rollover/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
