<?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>MEMOBALL.info &#187; Javascript</title>
	<atom:link href="http://www.memoball.info/tag/js/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.memoball.info</link>
	<description>All of my Memories</description>
	<lastBuildDate>Thu, 22 Jul 2010 06:17:14 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Javascripts cookie</title>
		<link>http://www.memoball.info/02/javascripts-cookie/</link>
		<comments>http://www.memoball.info/02/javascripts-cookie/#comments</comments>
		<pubDate>Fri, 06 Feb 2009 03:53:55 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://memoball.nabzer.com/?p=173</guid>
		<description><![CDATA[วันนี้ไปขุดดของเก่ามาใช้ เลยเอามาเขียนเป็นข้อมูลไว้กันลืมซะ เพราะน่าจะเป็นประโยชน์ในภายหลัง 

จาก WikiBall


			
อันนี้เป็น javascript object เกี่ยวกับ cookie ที่ไปรวบรวมมาจาก web อื่นแล้วนำมาเขียนรวมไว้


function jscookie(){
  this.get_offset_time = function(offset_str, factor)
  {
    if (factor == null) factor=1;

    var regs = null;
    var regex = new RegExp('^([0-9]+)\s*([smhdwnou])','i');
    regs = regex.exec(offset_str);

    if ( regs&#160;!= [...]]]></description>
			<content:encoded><![CDATA[<p>วันนี้ไปขุดดของเก่ามาใช้ เลยเอามาเขียนเป็นข้อมูลไว้กันลืมซะ เพราะน่าจะเป็นประโยชน์ในภายหลัง <span id="more-173"></span></p>
<div id="bodyContent">
<h3 id="siteSub"><a href="http://wiki.memoball.info/index.php/Source_%E0%B8%AA%E0%B8%B3%E0%B8%AB%E0%B8%A3%E0%B8%B1%E0%B8%9A%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B9%83%E0%B8%8A%E0%B9%89_javascript_%E0%B8%81%E0%B8%B1%E0%B8%9A_cookie">จาก WikiBall</a></h3>
<div id="contentSub"></div>
<div id="jump-to-nav"></div>
<p>			<!-- start content --></p>
<p>อันนี้เป็น javascript object เกี่ยวกับ cookie ที่ไปรวบรวมมาจาก web อื่นแล้วนำมาเขียนรวมไว้
</p>
<pre name="code" class="javascript">
function jscookie(){
  this.get_offset_time = function(offset_str, factor)
  {
    if (factor == null) factor=1;

    var regs = null;
    var regex = new RegExp('^([0-9]+)\s*([smhdwnou])','i');
    regs = regex.exec(offset_str);

    if ( regs&nbsp;!= null )
    {
      var amount = parseInt(regs[1]);
      var unit   = regs[2].toLowerCase();
    }
    else
    {
      var amount = parseInt(offset_str);
      var $unit  = 's';
    }

    var dt = new Date();
    var ts = dt.getTime();

    switch (unit)
    {
      case 'o':
      	ts = this.get_offset_time('30d', factor);
	break;
      case 'w':
        amount *= 7;
      case 'd':
        amount *= 24;
      case 'h':
        amount *= 60;
      case 'm':
        amount *= 60;
      case 's':
        amount *= 1000;
      case 'u':
        ts += amount * factor;
    }

    dt.setTime(ts);
    return dt.toGMTString();
  }

  this.create = function(name,value,time) {
    if (time) {
      var expires = &quot;; expires=&quot;+this.get_offset_time(time);
    }
    else
      var expires = &quot;&quot;;
    document.cookie = name+&quot;=&quot;+value+expires+&quot;; path=/&quot;;
  }

  this.read = function(name) {
    var nameEQ = name + &quot;=&quot;;
    var ca = document.cookie.split(';');
    for(var i=0;i &lt; 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;
  }

  this.erase = function(name) {
    this.create(name,&quot;&quot;,-1);
  }
}
</pre>
<p>ตัวอย่างการใช้งาน
</p>
<pre>
var cook = new jscookie();
cook.create('memoball','1234','1h');
alert(cook.read('memoball'));
</pre>
<p><!--<br />
NewPP limit report<br />
Preprocessor node count: 7/1000000<br />
Post-expand include size: 0/2097152 bytes<br />
Template argument size: 0/2097152 bytes<br />
Expensive parser function count: 0/100<br />
--></p>
<p><!-- Saved in parser cache with key memoball_wiki:pcache:idhash:17-0!1!0!!th!2!edit=0 and timestamp 20090825115816 --></p>
<div class="printfooter">
<h5>รับข้อมูลจาก (Reference) : </h5>
<p>จาก WikiBall : <a href="http://wiki.memoball.info/index.php/Source_%E0%B8%AA%E0%B8%B3%E0%B8%AB%E0%B8%A3%E0%B8%B1%E0%B8%9A%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B9%83%E0%B8%8A%E0%B9%89_javascript_%E0%B8%81%E0%B8%B1%E0%B8%9A_cookie">http://wiki.memoball.info/index.php/Source_สำหรับการใช้_javascript_กับ_cookie</a></div>
<div id='catlinks' class='catlinks'>
<div id="mw-normal-catlinks"><a href="http://wiki.memoball.info//index.php/%E0%B8%9E%E0%B8%B4%E0%B9%80%E0%B8%A8%E0%B8%A9:Categories" title="พิเศษ:Categories">หมวดหมู่</a>:&#32;<span dir='ltr'><a href="http://wiki.memoball.info//index.php?title=%E0%B8%AB%E0%B8%A1%E0%B8%A7%E0%B8%94%E0%B8%AB%E0%B8%A1%E0%B8%B9%E0%B9%88:Javascript&amp;action=edit&amp;redlink=1" class="new" title="หมวดหมู่:Javascript (ยังไม่ได้สร้าง)">Javascript</a></span></div>
</div>
<p>			<!-- end content --></p>
<div class="visualClear"></div>
</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.memoball.info/02/javascripts-cookie/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
