<?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>Kevin Pajak - Interactive Web Developer/Designer - BLOG &#187; jQuery</title>
	<atom:link href="http://www.kevinpajak.com/blog/tag/jquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.kevinpajak.com/blog</link>
	<description>Creative visionary, digital entrepreneur.</description>
	<lastBuildDate>Tue, 13 Apr 2010 02:01:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>How to log out a user who closes the browser window</title>
		<link>http://www.kevinpajak.com/blog/2010/02/10/how-to-log-out-a-user-who-closes-the-browser-window/</link>
		<comments>http://www.kevinpajak.com/blog/2010/02/10/how-to-log-out-a-user-who-closes-the-browser-window/#comments</comments>
		<pubDate>Thu, 11 Feb 2010 04:43:03 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Daily Journal]]></category>
		<category><![CDATA[Web Dev/Design]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[apps]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.kevinpajak.com/blog/?p=339</guid>
		<description><![CDATA[I would like to thank Brazilian software developer Daniel Melo for posting this code which helped me to solve a problem which was very pesky indeed, and in need of a solution. The problem occurred during a user&#8217;s logged-in session for a chat application I was building. This was the issue: the app is basically [...]]]></description>
			<content:encoded><![CDATA[<p>I would like to thank Brazilian software developer Daniel Melo for posting this code which helped me to solve a problem which was very pesky indeed, and in need of a solution. The problem occurred during a user&#8217;s logged-in session for a chat application I was building. This was the issue: the app is basically a live-chat client, which also shows all current users online, by name. If a logged-in user clicked the &#8220;Logout&#8221; link, all was good, no problem, his/her name was removed from the list of currently logged-on users. However, if the person just suddenly decided to end the chat session by just closing the browser and hitting &#8216;X&#8217; (as I myself might do!), the user was still showing as currently online, and NOT logged out (obviously this is an annoying issue). <span id="more-339"></span>After searching far and wide for this on the Internet, I came across the brilliant code I found at the link below on stackoverflow.com:</p>
<p><A HREF="http://stackoverflow.com/questions/1371757/how-to-kill-a-application-session-when-a-browser-window-is-closed" target="_blank"><B>&#8220;How to kill an application session when a browser window is closed?&#8221;</B></A></p>
<p>This code uses jQuery/Ajax in an absolutely brilliant and straightforward way. Basically what the code does is automatically load the contents of your &#8220;logoff.php&#8221; page, using the JavaScript <b>window.onbeforeunload</b> function (which is something that executes upon a user&#8217;s exiting the browser, refreshing the page, or submitting a form). Probably the most brilliant thing about this script is that it still uses the <em>onbeforeunload</em> function, BUT (and this was why it was of so much particular use to me for my particular case), let&#8217;s say that your web app page is relying on a form processor page that is on an external page, and not on the same page. If the user in this kind of case enters in their chat text, and then hits the submit button (but still is currently ON the page and actively participating in the current chat session), the typical <em>onbeforeunload</em> function if called, would execute (so basically, in this case, this would amount to the user being logged off every time he/she hit the &#8220;Post Message&#8221; button, and not JUST when the user closed the browser window).</p>
<p>So what this very clever script does is execute the contents of the script on your &#8220;logoff.php&#8221; page <b>onbeforeunload</b>, BUT <u>excepts the following cases:</u> (so it won&#8217;t get called if the user does the following things, and will only log the user out when he/she closes the browser window):</p>
<p>- Hitting the Submit button;<br />
- Clicking a link.</p>
<p>[The "magical" thing I will add too, after thinking about it, is that your 'logout.php' web page does not even have to be currently loaded on the browser - after all, the browser is being closed, right? This script executes your code all at once - like I said, fantastic! One other slightly unfortunate thing I found too in my extensive testing was that: this script works fine in Firefox and IE (and worked in Google Chrome, <em>after</em> not working the first time, insanely enough, but did not work in Opera or Safari :S). My sort of work-around for this was to at least add in code to my log-in page that sets the user's status to offline right away, then online once they are logged on and enter the chatroom].</p>
<p>Anyway, hope what I said here makes sense and is not too muddled an explanation, and&#8230; here is the code!:</p>
<div style="background: #EAE3E3; padding: 10px; border: 1px solid #000;">
/*<br />
* autoLogoff.js<br />
*<br />
* Every valid navigation (form submit, click on links) should<br />
* set this variable to true.<br />
*<br />
* If it is left to false the page will try to invalidate the<br />
* session via an AJAX call<br />
*/<br />
var validNavigation = false;</p>
<p>/*<br />
* Invokes the servlet /endSession to invalidate the session.<br />
* No HTML output is returned<br />
*/<br />
function endSession() {<br />
   $.get(&quot;&lt;whatever url will end your session&gt;&quot;);<br />
}</p>
<p>function wireUpEvents() {</p>
<p>  /*<br />
  * For a list of events that triggers onbeforeunload on IE<br />
  * check http://msdn.microsoft.com/en-us/library/ms536907(VS.85).aspx<br />
  */<br />
  window.onbeforeunload = function() {<br />
      if (!validNavigation) {<br />
         endSession();<br />
      }<br />
  }</p>
<p>  // Attach the event click for all links in the page<br />
  $(&quot;a&quot;).bind(&quot;click&quot;, function() {<br />
     validNavigation = true;<br />
  });</p>
<p>  // Attach the event submit for all forms in the page<br />
  $(&quot;form&quot;).bind(&quot;submit&quot;, function() {<br />
     validNavigation = true;<br />
  });</p>
<p>}</p>
<p>// Wire up the events as soon as the DOM tree is ready<br />
$(document).ready(function() {<br />
    wireUpEvents();  <br />
});
</div>
<p>From there, you just need to save this text in a file called &#8216;autoLogoff.js&#8217;, and call it toward the top of your page with the following code:</p>
<p>&lt;script type=&quot;text/javascript&quot; src=&quot;js/autoLogoff.js&quot;&gt;&lt;/script&gt;</p>
<p>I am making this post because this information was REALLY hard to find when I was searching for it, in the hopes that it can help you out with a similar project!</p>
<p>Again, here is the original posting for more and complete information:</p>
<p><A HREF="http://stackoverflow.com/questions/1371757/how-to-kill-a-application-session-when-a-browser-window-is-closed" target="_blank"><B>&#8220;How to kill an application session when a browser window is closed?&#8221;</B></p>
]]></content:encoded>
			<wfw:commentRss>http://www.kevinpajak.com/blog/2010/02/10/how-to-log-out-a-user-who-closes-the-browser-window/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery / Ajax live refresh</title>
		<link>http://www.kevinpajak.com/blog/2010/01/30/jquery-ajax-live-refresh/</link>
		<comments>http://www.kevinpajak.com/blog/2010/01/30/jquery-ajax-live-refresh/#comments</comments>
		<pubDate>Sun, 31 Jan 2010 04:20:56 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Daily Journal]]></category>
		<category><![CDATA[apps]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.kevinpajak.com/blog/?p=320</guid>
		<description><![CDATA[Running live, simultaneous beta tests using three different browsers for my wallpost app, with added jQuery/Ajax page refresh functionality. It is kicking some SERIOUS ass already (think: live chat possibilities, with saved record of all dialogues, that can be added to any page, threaded to any topic, etc) Yeah! . [Already, I&#8217;d like to thank [...]]]></description>
			<content:encoded><![CDATA[<p>Running live, simultaneous beta tests using three different browsers for my wallpost app, with added jQuery/Ajax page refresh functionality. It is kicking some SERIOUS ass already (think: live chat possibilities, with saved record of all dialogues, that can be added to any page, threaded to any topic, etc) Yeah! <img src='http://www.kevinpajak.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> .</p>
<p>[Already, I&#8217;d like to thank programmer Srinivas Tamada for <A HREF="http://www.9lessons.info/2009/07/auto-load-refresh-every-10-seconds-with.html" target="_blank"><B>this rockin&#8217; code!</B></A></p>
<p>And additionally, <A HREF="http://www.brightcherry.co.uk/scribbles/2009/02/26/jquery-auto-refresh-div-every-x-seconds/" target="_blank"><B>very special thanks to Maruf</B></A> for helping resolve an annoying IE issue:</p>
<p>After I modified the code, the stupid forced-caching issue of IE (which was delaying or not showing the updated list of all the latest posts) managed to get resolved. Here&#8217;s my modified code of the function:</p>
<p>&lt;script&gt;</p>
<p>   var refreshId = setInterval(function() {<br />
      $(&quot;#page_refresh&quot;).load(&#8216;show-comments.php?v=&#8217;+ Math.random());<br />
   }, 500);</p>
<p>&lt;/script&gt;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kevinpajak.com/blog/2010/01/30/jquery-ajax-live-refresh/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>jQuery toggle with tooltips combo</title>
		<link>http://www.kevinpajak.com/blog/2009/09/09/jquery-toggle-with-tooltips-combo/</link>
		<comments>http://www.kevinpajak.com/blog/2009/09/09/jquery-toggle-with-tooltips-combo/#comments</comments>
		<pubDate>Wed, 09 Sep 2009 19:02:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Daily Journal]]></category>
		<category><![CDATA[Web Dev/Design]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.kevinpajak.com/blog/?p=208</guid>
		<description><![CDATA[Structure containing BOTH jQuery toggle w. tooltips/image preview set up.]]></description>
			<content:encoded><![CDATA[<p>Structure containing BOTH jQuery toggle w. tooltips/image preview set up.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kevinpajak.com/blog/2009/09/09/jquery-toggle-with-tooltips-combo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery toggle</title>
		<link>http://www.kevinpajak.com/blog/2009/09/08/jquery-toggle/</link>
		<comments>http://www.kevinpajak.com/blog/2009/09/08/jquery-toggle/#comments</comments>
		<pubDate>Tue, 08 Sep 2009 21:50:03 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Daily Journal]]></category>
		<category><![CDATA[Web Dev/Design]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.kevinpajak.com/blog/?p=206</guid>
		<description><![CDATA[jQuery toggle set up.]]></description>
			<content:encoded><![CDATA[<p>jQuery toggle set up.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kevinpajak.com/blog/2009/09/08/jquery-toggle/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery tooltips</title>
		<link>http://www.kevinpajak.com/blog/2009/09/08/jquery-tooltips/</link>
		<comments>http://www.kevinpajak.com/blog/2009/09/08/jquery-tooltips/#comments</comments>
		<pubDate>Tue, 08 Sep 2009 18:57:39 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Daily Journal]]></category>
		<category><![CDATA[Web Dev/Design]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.kevinpajak.com/blog/?p=204</guid>
		<description><![CDATA[jQuery tooltips (with both text and image/screenshot preview) set up.]]></description>
			<content:encoded><![CDATA[<p>jQuery tooltips (with both text and image/screenshot preview) set up.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kevinpajak.com/blog/2009/09/08/jquery-tooltips/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

