<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>JAVASCRIPT Learning</title><link>http://www.ninenik.com</link><description>รวมบทความ JAVASCRIPT </description><language>th-TH</language><lastBuildDate>Fri, 10 Feb 2012 04:00:53 +0700</lastBuildDate><copyright>Copyright ninenik.com</copyright><image><title>CMSPro เว็บไซต์สำเร็จรูป</title><url>http://www.ninenik.com/images/logo_ninenik.gif</url><link>http://www.ninenik.com</link></image><item><title>แทรก +1 button ในเว็บจาก google plus</title><link>http://www.ninenik.com/แทรก_+1_button_ในเว็บจาก_google_plus-417.html</link><description><![CDATA[<p>เห็นหลายๆเว็บไซต์ เขาใส่ +1 button ในเว็บกันแล้ว อยากจะเอามาใส่ในเว็บ ninenik.com บ้าง<br />
<br />
เข้าไปอ่าน และปรับแต่งค่าต่างๆ แล้วเอาไปใส่เว็บได้เลยอย่างง่ายดายได้ที่<br />
<a href="http:// http://www.google.com/intl/en/webmasters/+1/button/index.html" target="_blank"><br />
http://www.google.com/intl/en/webmasters/+1/button/index.html</a><br />
<br />
Javascript Code แทรกไว้ก่อนแท็กปิด body หรือในแท็ก head<br />
<br />
&nbsp;</p>
<pre name="code" class="javascript:controls">
&lt;!-- Place this tag in your head or just before your close body tag --&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;https://apis.google.com/js/plusone.js&quot;&gt;
  {lang: 'th'} // สำหรับปรับแต่งภาษาไทย อังกฤษก็เปลี่ยนเป็น en
&lt;/script&gt;</pre>
<p><br />
<br />
Code ที่ต้องการแสดงปุ่ม +1 ไว้ตรงตำแหน่งที่ต้องการให้แสดง<br />
<br />
&nbsp;</p>
<pre name="code" class="php:controls">
&lt;!-- Place this tag where you want the +1 button to render --&gt;
&lt;g:plusone size=&quot;small&quot; callback=&quot;alert('OK man');&quot; href=&quot;http://www.ninenik.com&quot;&gt;&lt;/g:plusone&gt;</pre>
<p><br />
<br />
<strong>attrbute ภายในสำหรับปรับแต่ง</strong><br />
<strong>attrbute size ตอนนี้มี 4 แบบ </strong><br />
&nbsp;- small ขนาด 15px<br />
&nbsp;- medium ขนาด 20px<br />
&nbsp;- standard ขนาด 24px โดยที่หากใช้ขนาด standard ก็ไม่ต้องกำหนด attribute size<br />
&nbsp;- Tall ขนาด 60px<br />
<strong><br />
attribute callback</strong><br />
&nbsp;ใช้กำหนดสำหรับเรียกใช้ฟังก์ชัน javascript หลังจากคลิกที่ปุ่ม +1 แล้ว ว่าต้องการให้ทำอะไรเช่น<br />
&nbsp;&nbsp; callback=&quot;alert('OK man');&quot;&nbsp; หลังจากคลิกแล้วให้ขึ้น alert ว่า OK man<br />
<strong><br />
attribute count</strong><br />
&nbsp;ใช้กำหนดหากต้องการให้แสดงจำนวนคนที่กด +1 กี่คน หรือไม่<br />
&nbsp;count=&quot;false&quot;&nbsp; ไม่แสดง<br />
&nbsp;กรณีต้องการแสดง ไม่ต้องแทรก attribute count<br />
<br />
<strong>attribue href</strong><br />
&nbsp;ใช้กำหนด url ของหน้าเพจนั้นๆ จะกำหนดหรือไม่ ก็ได้ หากไม่กำหนด ก็จะใช้ url ของเพจนั้นเป็นหลัก <br />
<br />
<br />
อ่านรายละะอียดแบบเจาะลืก อย่างโปรได้ที่<br />
<br />
<a href="http://code.google.com/apis/+1button/" target="_blank">http://code.google.com/apis/+1button/</a></p>]]></description><pubDate>Sat, 16 Jul 2011 16:21:09 +0700</pubDate></item><item><title>ทบทวน JavaScript SDK ของ facebook</title><link>http://www.ninenik.com/ทบทวน_JavaScript_SDK_ของ_facebook-403.html</link><description><![CDATA[<p>JavaScript SDK ช่วยให้เราเข้าถึงลักษณะเด่นต่างๆ ของ Graph API&nbsp; ผ่านทาง JavaScript<br />
ฟังก์ชันที่ใช้งานใน JavaScript SDK เกือบทั้งหมด จำเป็นจะต้องมีการกำหนด APP ID <br />
สามารถลงทะเบียนขอรับ APP ID ได้จากลิ้งค์ต่อไปนี้ <br />
<a href="http://developers.facebook.com/setup/">http://developers.facebook.com/setup/</a></p>
<p>เริ่มต้น รูปแบบ การเรียกใช้งาน JavaScript SDK จะใช้รูปแบบต่อไปนี้ ในทุกๆ เนื้อหาที่เกี่ยวข้อง</p>
<pre class="php:controls" name="code">
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;
 &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;
 xmlns:fb=&quot;http://www.facebook.com/2008/fbml&quot;&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
&lt;title&gt;&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;



&lt;div id=&quot;fb-root&quot;&gt;&lt;/div&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://code.jquery.com/jquery-latest.min.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;http://connect.facebook.net/en_US/all.js&quot;&gt;&lt;/script&gt;
&lt;script&gt;
  window.fbAsyncInit = function() {
	  FB.init({
		appId  : 'YOUR APP ID', // ใส่ APP ID
		status : true, // check login status
		cookie : true, // enable cookies to allow the server to access the session
		xfbml  : true  // parse XFBML
	  });
  };
  (function() {
    var e = document.createElement('script'); e.async = true;
    e.src = document.location.protocol +
      '//connect.facebook.net/en_US/all.js';
    document.getElementById('fb-root').appendChild(e);
  }());  
&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
$(function(){
	// jQuery code
});
&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<p>&nbsp;</p>
<p>ตัวอย่างโค้ดด้านบน จะเป็นโค้ดเริ่มต้น ในการศึกษาการใช้ JavaScript SDK ในหัวข้อต่อๆ ไป</p>]]></description><pubDate>Tue, 15 Mar 2011 22:48:39 +0700</pubDate></item><item><title>แนะนำ ปลั๊กอิน comment ตัวใหม่ของ facebook</title><link>http://www.ninenik.com/แนะนำ_ปลั๊กอิน_comment_ตัวใหม่ของ_facebook-402.html</link><description><![CDATA[<p>facebook ปลั๊กอิน comment ตัวใหม่จะไม่อนุญาตให้บุคคลทั่วไป แสดง comment ได้ จะอนุญาต<br />
เฉพาะคนที่เป็นสมาชิกเท่านั้น</p>
<p>ลำดับการแสดงของ facebook ปลั๊กอิน comment ตัวใหม่ จะไม่สามารถกำหนดลำดับการแสดง<br />
รายการตามลำดับการโพสก่อน - หลัง ได้ แต่ลำดับการแสดง จะขึ้นอยู่กับว่า รายการ comment ใดๆ<br />
ที่มีคนกด like มากกว่า ก็จะอยู่ด้านบนหรือเหนือกว่า เหตุผลเพื่อป้องกัน spam หรือรายการ comment ที่ไม่เหมาะสม ให้แสดงอยู่หลังสุด หรือไม่แสดง</p>
<p>เมื่อมีการ comment และกำหนดให้แสดงไปยังหน้า wall ของผู้ comment ด้วยแล้ว<br />
หากมีคนมา reply (comment ต่อ) ต่อใน facebook wall จะทำให้ รายการ comment นั้น ก็จะมาแสดงที่ หน้าปลั๊กอินด้วย<br />
และในอีก กรณี หากมีคนมา reply (comment ต่อ) ที่หน้าปลั๊กอิน รายการ comment นั้น ก็จะไปแสดงที่ wall พร้อมทั้งมีการแจ้งเตือนว่ามีคนมา comment ด้วย</p>
<p><br />
ในส่วนของการจัดการ ผู้ดูแลสามารถกำหนดให้เลือกว่าจะทำการ comment โดยกรล็อกอินด้วย<br />
facebook หรือ yahoo ก็ได้ (อาจจะมีเพิ่มในภายหลัง) <br />
นอกจากนั้นในส่วนของการจัดการ <br />
สามารถกำหนดว่า ให้แสดงข้อความ comment นั้นทันทีเลยหรือไม่<br />
หรือว่า ให้แสดงเมื่อทำการตรวจสอบรายการ comment นั้นแล้ว<br />
สามารถทำการซ่อนรายการ comment ที่ไม่ต้องการได้<br />
สามารถ ban user ได้<br />
และอื่นๆ</p>
<p align="center">
  <object width="400" height="224">
    <param name="allowfullscreen" value="true">
    <param name="movie" value="http://www.facebook.com/v/10150433645890484">
    <embed type="application/x-shockwave-flash" width="400" height="224" src="http://www.facebook.com/v/10150433645890484" allowfullscreen="true">
  </object>
</p>
<p>เข้าไปอ่านตัวอย่างวฺิธีการใช้งานได้ด้วยตัวเองที่ <br />
<a href="http://developers.facebook.com/docs/reference/plugins/comments/">http://developers.facebook.com/docs/reference/plugins/comments/</a></p>
<p>หากต้องการให้สามารถจัดการ หรือดูแลรายการ comment ในหน้านั้นเลย สามารถกำหนด meta tag ดังนี้<br />
&nbsp;</p>
<pre class="php:controls" name="code">
&lt;meta property=&quot;fb:admins&quot; content=&quot;{YOUR_FACEBOOK_USER_ID}&quot;/&gt;</pre>
<p><font face="Courier New">หากต้องการให้สามารถจัดการ หรือดูแลรายการ comment ทั้งหมด สามารถกำหนด meta tag ดังนี้</font></p>
<pre class="php:controls" name="code">
&lt;meta property=&quot;fb:app_id&quot; content=&quot;{YOUR_APPLICATION_ID}&quot;&gt;</pre>
<p style="text-align: center"><font face="Courier New">ตัวอย่างหน้าตา facebook comment ใหม่<br />
<img width="520" height="483" alt="" src="/userfiles/image/new_facebook_comment.png" /></font></p>
<p><font face="Courier New">ตัวอย่างโค้ด การใช้งาน</font></p>
<pre class="php:controls" name="code">
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; 
&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;
 xmlns:fb=&quot;http://www.facebook.com/2008/fbml&quot;&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
&lt;title&gt;Facebook new comment&lt;/title&gt;

&lt;!--
หากต้องการให้สามารถจัดการ หรือดูแลรายการ comment ในหน้านั้นเลย สามารถกำหนด meta tag ดังนี้
--&gt;
&lt;meta property=&quot;fb:admins&quot; content=&quot;1234998873&quot;/&gt;
&lt;!--
หากต้องการให้สามารถจัดการ หรือดูแลรายการ comment ทั้งหมด สามารถกำหนด meta tag ดังนี้
&lt;meta property=&quot;fb:app_id&quot; content=&quot;{YOUR_APPLICATION_ID}&quot;&gt;
--&gt;
&lt;meta property=&quot;fb:app_id&quot; content=&quot;134358299911812&quot;&gt;
&lt;/head&gt;

&lt;body&gt;



&lt;div id=&quot;fb-root&quot;&gt;&lt;/div&gt;

&lt;fb:comments 
href=&quot;http://www.ninenik.com/fb/face_newcomment.php&quot; 
num_posts=&quot;3&quot; 
width=&quot;500&quot;&gt;
&lt;/fb:comments&gt;
&lt;!--
href กำหนด url ของหน้าที่แสดง
num_posts จำนวนที่ต้องการแสดง ต่อหนึ่งหน้า
width  ความกว้างที่ต้องการ
--&gt;
&lt;!--
&lt;script src=&quot;http://connect.facebook.net/en_US/all.js#appId={YOUR_APPLICATION_ID}&amp;amp;xfbml=1&quot;&gt;&lt;/script&gt;
--&gt;
&lt;script src=&quot;http://connect.facebook.net/en_US/all.js#appId=134358299911812&amp;amp;xfbml=1&quot;&gt;&lt;/script&gt;


&lt;/body&gt;
&lt;/html&gt;</pre>
<p>&nbsp;</p>]]></description><pubDate>Sun, 06 Mar 2011 15:04:58 +0700</pubDate></item><item><title>ยืนยันการเปลี่ยนแปลงข้อมูลใน select option ด้วย javascript อย่างง่าย</title><link>http://www.ninenik.com/ยืนยันการเปลี่ยนแปลงข้อมูลใน_select_option_ด้วย_javascript_อย่างง่าย-401.html</link><description><![CDATA[<p>ตัวอย่างโค้ดต่อไปนี้ เป็นการสร้างข้อความยืนยัน ในการเปลี่ยนแปลง ข้อมูลของ option select object หรือ ที่เรียกกันว่า list menu หรือ dropdown menu โดยหลักคือ เมื่อมีการเปลี่ยนแปลงข้อมูลในรายการ list menu จะมีข้อความแจ้งเตือนว่า ต้องการยืนยัน การเปลี่ยนแปลงข้อมูล หรือไม่ <br />
ถ้าเลือกยืนยันการเปลี่ยนแปลง คือ&nbsp; Yes<br />
ค่าของ list menu ก็จะเปลี่ยนแปลงไปตามที่เราเลือก<br />
ถ้าเลือก No <br />
ค่าของ list menu ก็จะเป็นค่าเดิม ก่อนที่เราจะทำการเปลี่ยนแปลงรายการ<br />
<strong>ตัวอย่าง</strong></p>
<p><select id="data1" onchange="chk_select2(this)" onfocus="chk_select1(this)" name="data1">
<option value="รายการ 1" selected="selected">รายการ 1</option>
<option value="รายการ 2">รายการ 2</option>
<option value="รายการ 3">รายการ 3</option>
</select> <script type="text/javascript">
var temp_val; // ตัวแปรสำหรับเก็บค่าเก่า สำหรับกรณียกเลิก
var selIdx; // ตัวแปรสำหรับเก็บค่ารายการเลือกเก่า สำหรับกรณียกเลิก
function chk_select1(obj){ // เก็บค่าข้อมูลเมื่อคลิก
	temp_val=obj.value;	 // เก็บค่าข้อมูลเมื่อคลิก
	selIdx = obj.selectedIndex; //  เก็บค่าข้อมูลเมื่อคลิก	 
}
function chk_select2(obj){ // ตรวจสอบเมื่อเลือกเปลี่ยนแปลงรายการ
	if(confirm("Are you sure?")){
		//  กำหนดคำสั่งตามต้องการถ้าเลือก Yes
		 alert("คุณได้ทำการยืนยันการเลือกรายการใหม่");
	}else{
		// คืนค่าตัวเลือกเดิม เมื่อไม่ยืนยันการเปลี่ยนแปลง
		obj.options[selIdx].selected=true; 
	}
}
</script></p>
<p>โค้ดตัวอย่าง</p>
<pre class="php:controls" name="code">
&lt;select name=&quot;data1&quot; id=&quot;data1&quot;  onfocus=&quot;chk_select1(this)&quot; onchange=&quot;chk_select2(this)&quot;&gt;
&lt;option value=&quot;รายการ 1&quot;&gt;รายการ 1&lt;/option&gt;
&lt;option value=&quot;รายการ 2&quot;&gt;รายการ 2&lt;/option&gt;
&lt;option value=&quot;รายการ 3&quot;&gt;รายการ 3&lt;/option&gt;
&lt;/select&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
var temp_val; // ตัวแปรสำหรับเก็บค่าเก่า สำหรับกรณียกเลิก
var selIdx; // ตัวแปรสำหรับเก็บค่ารายการเลือกเก่า สำหรับกรณียกเลิก
function chk_select1(obj){ // เก็บค่าข้อมูลเมื่อคลิก
	temp_val=obj.value;	 // เก็บค่าข้อมูลเมื่อคลิก
	selIdx = obj.selectedIndex; //  เก็บค่าข้อมูลเมื่อคลิก	 
}
function chk_select2(obj){ // ตรวจสอบเมื่อเลือกเปลี่ยนแปลงรายการ
	if(confirm(&quot;Are you sure?&quot;)){
		//  กำหนดคำสั่งตามต้องการถ้าเลือก Yes
		 alert(&quot;คุณได้ทำการยืนยันการเลือกรายการใหม่&quot;);
	}else{
		// คืนค่าตัวเลือกเดิม เมื่อไม่ยืนยันการเปลี่ยนแปลง
		obj.options[selIdx].selected=true; 
	}
}
&lt;/script&gt;</pre>
<p>&nbsp;</p>]]></description><pubDate>Thu, 24 Feb 2011 08:00:00 +0700</pubDate></item><item><title>เพิ่มเติม การใช้งาน popup แบบ showModalDialog อย่างสมบูรณ์</title><link>http://www.ninenik.com/เพิ่มเติม_การใช้งาน_popup_แบบ_showModalDialog_อย่างสมบูรณ์-391.html</link><description><![CDATA[<p>จากเนื้อหา <br />
การสร้าง popup ที่แตกต่าง ด้วยวิธี showModalDialog <br />
<a href="http://www.ninenik.com/การสร้าง_popup_ที่แตกต่าง_ด้วยวิธี_showModalDialog__-314.html">http://www.ninenik.com/การสร้าง_popup_ที่แตกต่าง_ด้วยวิธี_showModalDialog__-314.html</a></p>
<p>เป็นการแนะนำการสร้าง รูปแบบ popup อีกรูปแบบหนึ่ง ซึ่งอธิบายในหัวข้อตามลิ้งค์ข้างต้น<br />
อย่างไรก็ตาม ไม่ได้อธิบาย รูปแบบการใช้งานที่ต่อเนื่อง ในหัวข้อดังกล่าว ทำให้การนำเอา<br />
ไปใช้งาน จึงไม่มีประสิทธิภาพมากนัก</p>
<p><br />
ในที่นี้จะขออธิบายการใช้งาน เท่าที่จำเป็นอย่างสมบูรณ์ คือ เป็นไปในรูปแบบดังนี้</p>
<p>เมื่อคลิก แสดง popup และ popup ที่เปิดขึ้นมามีแบบฟอร์มสำหรับบันทึกข้อมูล <br />
ก็จะทำการ submit แบบฟอร์มในหน้า popup ได้<br />
และ สามารถที่จะกำหนดให้ปิด popup นั้นอัตโนมัติเมื่อ submit ข้อมูลแล้ว หรือสร้างปุ่มสำหรับปิด ก็ได้<br />
และ เมื่อปิด หน้า popup แล้ว ให้หน้าที่ เปิด popup รีโหลดตัวเอง หรือ ลิ้งค์ที่หน้าอื่นตามต้องการได้</p>
<p>ตัวอย่าง<br />
<a href="http://www.ninenik.com/demo/parent_open_showmodaldialog.php">http://www.ninenik.com/demo/parent_open_showmodaldialog.php</a></p>
<p>ตัวอย่างโค้ดไฟล์ทดสอบ จะมี 2 ไฟล์ชื่อ <br />
parent_open_showmodaldialog.php<br />
popup_modaldialog.php</p>
<p>ตัวอย่างโค้ดไฟล์ parent_open_showmodaldialog.php</p>
<pre class="php:controls" name="code">
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;
 &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
&lt;title&gt;parent page open showmodaldialog&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;


&lt;input name=&quot;ddd&quot; type=&quot;text&quot; id=&quot;ddd&quot; /&gt;
&lt;button onclick=&quot;popupModal('popup_modaldialog.php',500,200);&quot;&gt;Sample Popup&lt;/button&gt;

&lt;script type=&quot;text/javascript&quot;&gt;
var Argu=window; // สร้างตัวแปร สำหรับส่งค่า window object ไปที่ popup
function popupModal(url,width,height){
	var myDate=new Date();
	var setUniqe=myDate.getTime(); // ใช้สำหรับ ป้องกันการ cache กรณีกำลังทดสอบ
	var diaxFeature=&quot;dialogWidth:&quot;+width+&quot;px;&quot;
	+&quot;dialogHeight:&quot;+height+&quot;px;&quot;
/*	+&quot;dialogLeft:&quot;+width+&quot;px;&quot;
	+&quot;dialogTop:&quot;+width+&quot;px;&quot;		*/
	+&quot;center:yes;&quot;
	+&quot;edge:raised;&quot; // sunken | raised 
	+&quot;resizable:no;&quot;
	+&quot;status:no;&quot;
	+&quot;scroll:no;&quot;;	
	var str =  window.showModalDialog(url+&quot;?&quot;+setUniqe,Argu, diaxFeature);
	// กรณีไม่ใช้ setUniqe
	//  window.showModalDialog(url,&quot;&quot;, diaxFeature); 
}
&lt;/script&gt;
&lt;br /&gt;
&lt;br /&gt;
หมายเหตุ เพื่อให้เห็นว่าเมื่อปิด popup แล้ว ไฟล์หน้าหลัก รีเฟรส หรือไม่ ให้กรอก ข้อความอะไรก็ได้&lt;br /&gt;
ใน textbox ก่อนกดปุ่ม คำว่า Sample Popup
&lt;/body&gt;
&lt;/html&gt;</pre>
<p>ตัวอย่างโค้ดไฟล์ popup_modaldialog.php</p>
<pre class="php:controls" name="code">
&lt;?php
header(&quot;Content-type:text/html; charset=UTF-8&quot;);              
header(&quot;Cache-Control: no-store, no-cache, must-revalidate&quot;);             
header(&quot;Cache-Control: post-check=0, pre-check=0&quot;, false);   
?&gt;
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; 
&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
&lt;base target=&quot;_self&quot;&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
&lt;title&gt;popup modaldialog&lt;/title&gt;
&lt;style type=&quot;text/css&quot;&gt;
body{
	padding:10px;
	color:#FF0;
	background:#333;	
}
h4{
	color:#F90;
	text-decoration:underline;	
}
&lt;/style&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
var oMyObject = window.dialogArguments; // รับค่า window object มา
oMyObject.location='parent_open_showmodaldialog.php'; // ชื่อไฟล์หน้าหลัก ที่ต้องการ โหลด
&lt;?php
// 3 บรรทัดด้านล่าง เป็นตัวอย่าง ใช้งานกรณีใช้ php ปิด popup
//	if(count($_POST)&gt;0){
//		echo &quot;window.close();&quot;;	
//	}
?&gt;
&lt;/script&gt;

&lt;/head&gt;

&lt;body&gt;
&lt;pre&gt;
&lt;?php print_r($_POST); ?&gt;
&lt;/pre&gt;
&lt;form id=&quot;form1&quot; name=&quot;form1&quot; method=&quot;post&quot; action=&quot;&quot; &gt;
  &lt;input type=&quot;text&quot; name=&quot;textfield&quot; id=&quot;textfield&quot; /&gt;
  &lt;input type=&quot;submit&quot; name=&quot;button&quot; id=&quot;button&quot; value=&quot;Submit&quot; /&gt;
  &lt;input type=&quot;button&quot; name=&quot;button2&quot; id=&quot;button2&quot; value=&quot;Close&quot; onclick=&quot;window.close();&quot; /&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<p><br />
บรรทัดที่ 2-4 สำหรับป้องกันการจำค่าเก่า<br />
บรรทัดที่ 10 จำเป็นต้องใส่ &lt;base target=&quot;_self&quot;&gt; เพื่อให้สามารถใช้งาน หน้า popup<br />
สำหรับ submit ข้อมูลในหน้าดังกล่าวได้<br />
บรรทัดที่ 25 เป็นการรับค่า object จากหน้าหลัก ในที่นี้คือ window object หน้าหลัก<br />
บรรทัดที่ 26 ให้ object window หน้าหลักโหลดไฟล์ที่ต้องการ หากต้องการ รีเฟรสหน้า<br />
ที่เปิด popup ให้กำหนดเป็นชือไฟล์ นั้นๆ<br />
บรรทัดที่ 27-32 เป็นเพียงตัวอย่าง หากจะใช้งาน การปิด popup ด้วย php</p>
<p>ทดสอบกรอกค่าอะไรก็ได้ในหน้า popup แล้วกด submit ก็จะแสดงข้อมูลการ submit ใน<br />
หน้านั้น แล้วคลิกที่ปุ่ม close หากต้องการปิด แล้วหน้าหลักจะทำการ รีโหลดอีกครั้ง</p>]]></description><pubDate>Wed, 29 Dec 2010 08:00:00 +0700</pubDate></item><item><title>ทบทวน การจัดการกับ ตัวแปร array ใน javascript ด้วย ฟังก์ชัน ตอนที่ 2</title><link>http://www.ninenik.com/ทบทวน_การจัดการกับ_ตัวแปร_array_ใน_javascript_ด้วย_ฟังก์ชัน_ตอนที่_2-343.html</link><description><![CDATA[<p><strong>ใช้ฟังก์ชัน sort()&nbsp; ในการจัดการ กับตัวแปร array</strong><br />
<br />
<strong>sort()</strong> ใช้สำหรับ เรียงลำดับค่า ในตัวแปร array ตามตัวอักษร รองรับการใช้งาน กับการเรียงอักษรภาษาไทย<br />
ไม่สามารถใช้ได้กับการเรียงตัวเลข เช่น ถ้ามีเลข 5 กับ 40 การเรียงลำดับด้วย sort() จะไม่สามารถทำได้<br />
ทำให้ 40 จะมาก่อนเลข 5 แทนที่จะเป็น เลข 5 มาก่อนเลข 40 อย่างไรก็ตาม หากจำเป็นต้องใช้การเรียงตัวเลข<br />
สามารถสร้างฟังก์ชัน สำหรับการเปรียบเทียบค่าเข้ามาช่วยได้ <br />
<br />
การคืนค่าจะคืนค่ารายการ array ที่มีการเรียงลำดับเรียบร้อยแล้ว มีผลทำให้ตัวแปร array มีการเปลี่ยนแปลง</p>
<pre class="javascript:controls" name="code">
// ตัวอย่างการใช้งาน  
var cars=[&quot;Toyota&quot;,&quot;Honda&quot;,&quot;Isuzu&quot;,&quot;Mitsubishi&quot;];  // ตัวแปร array  
  
var carsUseSort=cars.sort();
// จะได้ cars=[&quot;Honda&quot;,&quot;Isuzu&quot;,&quot;Mitsubishi&quot;,&quot;Toyota&quot;];
// แล้วคืนค่ากลับมาเป็น array ที่มีการเรียงลำดับใหม่แล้ว
// ทำให้ตัวแปร carsUseSort=[&quot;Honda&quot;,&quot;Isuzu&quot;,&quot;Mitsubishi&quot;,&quot;Toyota&quot;]; เท่ากับตัวแปร cars</pre>
<pre class="javascript:controls" name="code">
// ตัวอย่างการใช้งาน กรณี การเรียงลำดับตัวเลข จาก น้อยไปหามาก
var num = [&quot;10&quot;, &quot;5&quot;, &quot;40&quot;, &quot;25&quot;, &quot;100&quot;, &quot;1&quot;]; // ตัวแปร array
function sortNumber(a,b){ // ฟังก์ชันสำหรับเปรียบเทียบค่า ใช้ในการจัดเรียงกรณีตัวเลข
return a - b;
}

var numSort=num.sort(sortNumber);
// จะได้ num=[&quot;1&quot;, &quot;5&quot;, &quot;10&quot;, &quot;25&quot;, &quot;40&quot;, &quot;100&quot;]; 
// แล้วคืนค่ากลับมาเป็น array ที่มีการเรียงลำดับใหม่แล้ว
// ทำให้ตัวแปร numSort=[&quot;1&quot;, &quot;5&quot;, &quot;10&quot;, &quot;25&quot;, &quot;40&quot;, &quot;100&quot;]; เท่ากับตัวแปร num</pre>
<pre class="javascript:controls" name="code">
// ตัวอย่างการใช้งาน กรณี การเรียงลำดับตัวเลข จาก มากไปหาน้อย
var num = [&quot;10&quot;, &quot;5&quot;, &quot;40&quot;, &quot;25&quot;, &quot;100&quot;, &quot;1&quot;]; // ตัวแปร array
function sortNumber(a,b){ // ฟังก์ชันสำหรับเปรียบเทียบค่า ใช้ในการจัดเรียงกรณีตัวเลข
return b - a;
}


var numSort=num.sort(sortNumber);
// จะได้ num=[&quot;1&quot;, &quot;5&quot;, &quot;10&quot;, &quot;25&quot;, &quot;40&quot;, &quot;100&quot;]; 
// แล้วคืนค่ากลับมาเป็น array ที่มีการเรียงลำดับใหม่แล้ว
// ทำให้ตัวแปร numSort=[&quot;1&quot;, &quot;5&quot;, &quot;10&quot;, &quot;25&quot;, &quot;40&quot;, &quot;100&quot;]; เท่ากับตัวแปร num</pre>
<p>&nbsp;</p>
<p>ใช้ฟังก์ชัน <strong>splice()</strong>&nbsp; ในการจัดการ กับตัวแปร array</p>
<p><br />
<strong>splice(index,howmany,element1,.....,elementX) </strong><br />
ใช้สำหรับ เพิ่มค่าเข้าไปในตัวแปร array <br />
และ/หรือ ลบค่าออกจากตัวแปร array (เพิ่ม หรือ ลบ อย่างใดอย่างอย่างหนึ่ง หรือ ทั้งเพิ่ม และลบพร้อมกัน)<br />
คืนค่าที่ทำการลบออก กรณีกำหนดให้มีการลบ<br />
โดยทำให้ตัวแปร array มีการเปลี่ยนแปลง<br />
<strong>index </strong>คือ ตำแหน่งที่ต้องการ เพิ่ม หรือลบ ค่าในตัวแปร array<br />
<strong>howmany</strong> คือ จำนวนค่าที่ต้องการ ลบ ถ้าเป็น 0 หมายถึง ไม่มีการลบค่าในตัวแปร array<br />
<strong>element1, ..., elementX</strong> คือ ค่าใหม่ที่ต้องการเพิ่มเข้าไปในตัวแปร array กำหนด หรือไม่ก็ได้</p>
<pre class="javascript:controls" name="code">
// ตัวอย่างการใช้งาน  กรณีเพิ่มค่าเข้าไปในตัวแปร array ตำแหน่งที่ 2
var cars=[&quot;Toyota&quot;,&quot;Honda&quot;,&quot;Isuzu&quot;,&quot;Mitsubishi&quot;];  // ตัวแปร array  
  
var carsUseSplice=cars.splice(2,0,&quot;Ford&quot;);
// มีผลให้ตัวแปร cars=[&quot;Toyota&quot;,&quot;Honda&quot;,&quot;Ford&quot;,&quot;Isuzu&quot;,&quot;Mitsubishi&quot;];
// ไม่มีการคืนค่า เนื่องจากไม่มีการลบค่าใดๆ ออกจากตัวแปร
// ทำให้ carsUseSplice=&quot;&quot;;</pre>
<pre class="javascript:controls" name="code">
// ตัวอย่างการใช้งาน  กรณีลบ หนึ่งค่าออกจากตำแหน่งที่ 2 และเพิ่มค่าใหม่เข้าไปในตำแหน่งที่ 2
// ลบ และ เพิ่ม
var cars=[&quot;Toyota&quot;,&quot;Honda&quot;,&quot;Isuzu&quot;,&quot;Mitsubishi&quot;];  // ตัวแปร array  
  
var carsUseSplice=cars.splice(2,1,&quot;Ford&quot;);
// มีผลให้ตัวแปร cars=[&quot;Toyota&quot;,&quot;Honda&quot;,&quot;Ford&quot;,&quot;Mitsubishi&quot;];
// คืนค่า ตัวที่ลบ เท่ากับ Isuzu เนื่องจากมีการกำหนด จำนวนที่ต้องการลบ เท่ากับ 1
// ทำให้ carsUseSplice=&quot;Isuzu&quot;;</pre>
<pre class="javascript:controls" name="code">
// ตัวอย่างการใช้งาน  กรณีลบ สองค่าออกจากตำแหน่งที่ 2 และเพิ่มค่าใหม่เข้าไปในตำแหน่งที่ 2
// ลบ และ เพิ่ม
var cars=[&quot;Toyota&quot;,&quot;Honda&quot;,&quot;Isuzu&quot;,&quot;Mitsubishi&quot;];  // ตัวแปร array  
  
var carsUseSplice=cars.splice(2,2,&quot;Ford&quot;);
// มีผลให้ตัวแปร cars=[&quot;Toyota&quot;,&quot;Honda&quot;,&quot;Ford&quot;];
// คืนค่า ตัวที่ลบ เท่ากับ Isuzu,Mitsubishi เนื่องจากมีการกำหนด จำนวนที่ต้องการลบ เท่ากับ 2
// ทำให้ carsUseSplice=&quot;Isuzu,Mitsubishi&quot;;
</pre>
<p>&nbsp;</p>
<p>ใช้ฟังก์ชัน <strong>toString()</strong>&nbsp; ในการจัดการ กับตัวแปร array</p>
<p><strong>toString()</strong> ใช้สำหรับ แปลงค่า array เป็น string และคืนค่าเป็นข้อความคั่นด้วยเครื่องหมาย (,) <br />
โดยที่ตัวแปร array ไม่มีการเปลี่ยนแปลง<br />
&nbsp;</p>
<pre class="javascript:controls" name="code">
// ตัวอย่างการใช้งาน  
var cars=[&quot;Toyota&quot;,&quot;Honda&quot;,&quot;Isuzu&quot;,&quot;Mitsubishi&quot;];  // ตัวแปร array  
  
var carsUseToString=cars.toString();
// จะได้ carsUseToString=&quot;Toyota,Honda,Isuzu,Mitsubishi&quot;;
// โดยที่ตัวแปร cars ไม่มีการเปลี่ยนแปลง</pre>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>ใช้ฟังก์ชัน <strong>valueOf()&nbsp; </strong>ในการจัดการ กับตัวแปร array</p>
<p><strong>valueOf()</strong> ใช้สำหรับ แสดงค่าทั้งหมดในตัวแปร array และคั่นแต่ละค่าด้วย comma (,) <br />
โดยที่ตัวแปร array ไม่มีการเปลี่ยนแปลง<br />
&nbsp;</p>
<pre class="javascript:controls" name="code">
// ตัวอย่างการใช้งาน  
var cars=[&quot;Toyota&quot;,&quot;Honda&quot;,&quot;Isuzu&quot;,&quot;Mitsubishi&quot;];  // ตัวแปร array  
  
var carsUseValueOf=cars.valueOf();
// จะได้ carsUseValueOf=&quot;Toyota,Honda,Isuzu,Mitsubishi&quot;;
// โดยที่ตัวแปร cars ไม่มีการเปลี่ยนแปลง</pre>
<p>&nbsp;</p>]]></description><pubDate>Wed, 22 Sep 2010 08:00:00 +0700</pubDate></item><item><title>ทบทวน การจัดการกับ ตัวแปร array ใน javascript ด้วย ฟังก์ชัน ตอนที่ 1</title><link>http://www.ninenik.com/ทบทวน_การจัดการกับ_ตัวแปร_array_ใน_javascript_ด้วย_ฟังก์ชัน_ตอนที่_1-342.html</link><description><![CDATA[<p><strong>ใช้ฟังก์ชัน concat()&nbsp; ในการจัดการ กับตัวแปร array</strong></p>
<p><strong>concat() </strong>ใช้สำหรับสร้างตัวแปร array ใหม่จาก การรวมตัวแปร array ตั้งแต่ 2 ตัวขึ้นไป โดยที่ตัวแปร array ที่นำมา รวมกันนั้น ยังเหมือนเดิม ไม่มีการเปลี่ยนแปลงใดๆ<br />
&nbsp;</p>
<pre class="javascript:controls" name="code">
// ตัวอย่าง กรณ๊รวมตัวแปร array 2 ตัว
var alpha = [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;];  
var numeric = [1, 2, 3];  

var alphaNumeric = alpha.concat(numeric);  
// สร้าง array [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;, 1, 2, 3]; โดยที่ array ชื่อ alpha และ numeric ไม่มีการเปลี่ยนแปลง
// ตัวแปร array ใหม่ที่ได้คือ ชื่อ alphaNumeric มีค่าเท่ากับ [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;, 1, 2, 3];</pre>
<pre class="javascript:controls" name="code">
// ตัวอย่าง กรณ๊รวมตัวแปร array 3 ตัว
var num1 = [1, 2, 3];  
var num2 = [4, 5, 6];  
var num3 = [7, 8, 9];  

var nums = num1.concat(num2, num3);  
// สร้าง  array [1, 2, 3, 4, 5, 6, 7, 8, 9]; โดยที่ num1, num2, num3  ไม่มีการเปลี่ยนแปลง
// ตัวแปร array ใหม่ที่ได้คือ ชื่อ nums มีค่าเท่ากับ [1, 2, 3, 4, 5, 6, 7, 8, 9];</pre>
<pre class="javascript:controls" name="code">
// ตัวอย่าง กรณีรวมตัวแปร array กับค่าที่ต้องการ
var alpha = ['a', 'b', 'c'];  
  
var alphaNumeric = alpha.concat(1, [2, 3]);  
// สร้าง array [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;, 1, 2, 3], โดยที่ alpha ไม่มีการเปลี่ยนแปลง
// ตัวแปร array ใหม่ที่ได้คือ ชื่อ alphaNumeric มีค่าเท่ากับ [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;, 1, 2, 3];</pre>
<p>&nbsp;</p>
<p><strong>ใช้ฟังก์ชัน join()&nbsp; ในการจัดการ กับตัวแปร array</strong></p>
<p><strong>join()</strong> ใช้สำหรับ การนำค่าแต่ละค่าในตัวแปร array มารวมกันเป็นข้อความ และส่งค่ากลับเป็นข้อความ ที่มีตัวคั่นค่าตัวแปรแต่ละค่า ตามที่กำหนด ถ้าไม่ได้กำหนด จะเป็นเครื่องหมาย comma (,) ให้โดยอัตโนมัติ<br />
&nbsp;</p>
<pre class="javascript:controls" name="code">
//ตัวอย่างการใช้งาน
var cars=[&quot;Toyota&quot;,&quot;Honda&quot;,&quot;Isuzu&quot;];  // ตัวแปร array

var carsUseJoin=cars.join(); // ไม่ได้กำหนดตัวคั่นค่าตัวแปร หรือตัวแบ่ง
// ผลที่ได้คือ เป็นการนำค่าในตัวแปร array ชื่อ cars มารวมกัน หรือเรียงต่อกัน เป็นข้อความ
// ใหม่ และคั่นแต่ละค่าด้วย comma (,)
// จะได้ตัวแปร carsUseJoin เป็น ตัวแปรประเภท String 
// มีค่าเท่ากับ carsUseJoin=&quot;Toyota,Honda,Isuzu&quot;;</pre>
<pre class="javascript:controls" name="code">
// ตัวอย่าง กรณีกำหนดค่าตัวแบ่ง
var cars=[&quot;Toyota&quot;,&quot;Honda&quot;,&quot;Isuzu&quot;];  // ตัวแปร array

var carsUseJoin=cars.join(&quot; and &quot;); // กำหนดตัวคั่นค่าตัวแปร หรือตัวแบ่ง
// ผลที่ได้คือ เป็นการนำค่าในตัวแปร array ชื่อ cars มารวมกัน หรือเรียงต่อกัน เป็นข้อความ
// ใหม่ และคั่นแต่ละค่าด้วย and
// จะได้ตัวแปร carsUseJoin เป็น ตัวแปรประเภท String 
// มีค่าเท่ากับ carsUseJoin=&quot;Toyota and Honda and Isuzu&quot;;</pre>
<p>&nbsp;</p>
<p><strong>ใช้ฟังก์ชัน pop()&nbsp; ในการจัดการ กับตัวแปร array</strong></p>
<p><strong>pop()</strong> ใช้สำหรับ ลบค่าตัวสุดท้ายออกจากตัวแปร array แล้วคืนค่านั้นกลับมา <br />
มีผลให้ตัวแปร array มีการเปลี่ยนแปลง<br />
&nbsp;</p>
<pre class="javascript:controls" name="code">
// ตัวอย่างการใช้งาน
var cars=[&quot;Toyota&quot;,&quot;Honda&quot;,&quot;Isuzu&quot;];  // ตัวแปร array

var carsUsePop=cars.pop(); // ลบค่าตัวสุดท้าย Isuzu ออกจากตัวแปร array ชื่อ cars
// มีผลให้ตัวแปร array cars=[&quot;Toyota&quot;,&quot;Honda&quot;]; และ length ลดเหลือ 2 
// จากนั้นคืนค่าที่ลบออก มา แล้วกำหนดไว้ที่ตัวแปร carsUsePop
// จะได้ตัวแปร carsUsePop=&quot;Isuzu&quot;;</pre>
<p><br />
&nbsp;</p>
<p><strong>ใช้ฟังก์ชัน push()&nbsp; ในการจัดการ กับตัวแปร array</strong></p>
<p><strong>push()</strong> ใช้สำหรับ เพิ่มค่าเข้าไปในตัวแปร array โดยต่อท้าย จากค่าเดิม แล้วคืนค่าจำนวนรายการทั้งหมด ของตัวแปร array กลับมา มีผลให้ตัวแปร array มีการเปลี่ยนแปลง <br />
&nbsp;</p>
<pre class="javascript:controls" name="code">
// ตัวอย่างการใช้งาน กรณีเพิ่มเพียงค่าเดียว
var cars=[&quot;Toyota&quot;,&quot;Honda&quot;,&quot;Isuzu&quot;];  // ตัวแปร array

var carsUsePush=cars.push(&quot;Mitsubishi&quot;); // เพิ่มค่า Mitsubishi เข้าไปต่อท้ายค่าตัวแปร array เดิม 
// มีผลให้ตัวแปร array cars=[&quot;Toyota&quot;,&quot;Honda&quot;,&quot;Isuzu&quot;,&quot;Mitsubishi&quot;]; 
// จากนั้นคืนค่าจำนวนรายการทั้งหมด ของตัวแปร array cars แล้วกำหนดไว้ที่ตัวแปร carsUsePush
// จะได้ตัวแปร carsUsePush=4;</pre>
<pre class="javascript:controls" name="code">
// ตัวอย่างการใช้งาน กรณีเพิ่มหลายค่า
var cars=[&quot;Toyota&quot;,&quot;Honda&quot;,&quot;Isuzu&quot;];  // ตัวแปร array

var carsUsePush=cars.push(&quot;Mitsubishi&quot;,&quot;Ford&quot;); 
// เพิ่มค่า Mitsubishi และ Ford เข้าไปต่อท้ายค่าตัวแปร array เดิม 
// มีผลให้ตัวแปร array cars=[&quot;Toyota&quot;,&quot;Honda&quot;,&quot;Isuzu&quot;,&quot;Mitsubishi&quot;,&quot;Ford&quot;]; และ length เพิ่มขั้น
// จากนั้นคืนค่าจำนวนรายการทั้งหมด ของตัวแปร array cars แล้วกำหนดไว้ที่ตัวแปร carsUsePush
// จะได้ตัวแปร carsUsePush=5;</pre>
<p>&nbsp;</p>
<p><strong>ใช้ฟังก์ชัน reverse()&nbsp; ในการจัดการ กับตัวแปร array</strong></p>
<p><strong>reverse()</strong> ใช้สำหรับ กลับลำดับค่าของตัวแปร array เช่น ค่าจากเดิม คือ 1 2 3 4 เมื่อใช้ reverse() ลำดับค่าใหม่จะเท่ากับ 4 3 2 1 มีผลให้ตัวแปร array มีการเปลี่ยนแปลง <br />
&nbsp;</p>
<pre class="javascript:controls" name="code">
// ตัวอย่างการใช้งาน 
var cars=[&quot;Toyota&quot;,&quot;Honda&quot;,&quot;Isuzu&quot;,&quot;Mitsubishi&quot;];  // ตัวแปร array
// ค่าเดิม 
// cars[0]=&quot;Toyota&quot;;
// cars[1]=&quot;Honda&quot;;
// cars[2]=&quot;Isuzu&quot;;
// cars[3]=&quot;Mitsubishi&quot;;

var carsUseReverse=cars.reverse(); // ทำการกลับลำดับรายการตัวแปร array
// มีผลให้ตัวแปร array cars=[&quot;Mitsubishi&quot;,&quot;Isuzu&quot;,&quot;Honda&quot;,&quot;Toyota&quot;]; 
// ค่าใหม่
// cars[0]=&quot;Mitsubishi&quot;;
// cars[1]=&quot;Isuzu&quot;;
// cars[2]=&quot;Honda&quot;;
// cars[3]=&quot;Toyota&quot;;
// จากนั้นนำตัวแปร array ที่ทำการกลับลำดับรายการไปเก็บไว้ในตัวแปร carsUseReverse
// จะได้ตัวแปร carsUseReverse=[&quot;Mitsubishi&quot;,&quot;Isuzu&quot;,&quot;Honda&quot;,&quot;Toyota&quot;];  ซึ่งเท่ากับตัวแปร cars</pre>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>ใช้ฟังก์ชัน shift()&nbsp; ในการจัดการ กับตัวแปร array</strong></p>
<p><strong>shift()</strong> ใช้สำหรับ ลบค่าตัวแรกออกจากตัวแปร array แล้วคืนค่านั้นกลับมา <br />
มีผลให้ตัวแปร array มีการเปลี่ยนแปลง<br />
&nbsp;</p>
<pre class="javascript:controls" name="code">
// ตัวอย่างการใช้งาน
var cars=[&quot;Toyota&quot;,&quot;Honda&quot;,&quot;Isuzu&quot;];  // ตัวแปร array

var carsUseShift=cars.shift(); // ลบค่าตัวแรก Toyota ออกจากตัวแปร array ชื่อ cars
// มีผลให้ตัวแปร array cars=[&quot;Honda&quot;,&quot;Isuzu&quot;];  และ length ลดเหลือ 2 
// จากนั้นคืนค่าที่ลบออก มา แล้วกำหนดไว้ที่ตัวแปร carsUseShift
// จะได้ตัวแปร carsUseShift=&quot;Toyota&quot;;</pre>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>ใช้ฟังก์ชัน slice()&nbsp; ในการจัดการ กับตัวแปร array</strong></p>
<p><strong>slice(start,end) </strong>ใช้สำหรับ ดึงค่าจากตำแหน่งที่ต้องการในตัวแปร array แล้วคืนค่านั้นกลับมา <br />
ไม่มีผลให้ตัวแปร array มีการเปลี่ยนแปลง<br />
start คือ ตำแหน่งเริ่มต้นที่ต้องการดึงค่าจากตัวแปร array เริ่มต้นเท่ากับ 0 สามารถเป็นค่าติดลบได้<br />
end คือ ตำแหน่งสุดท้ายที่ต้องการ ไม่อิงตาม key นั้นหมายถึงนับตัวแรกเท่ากับ 1 ต่างจาก start ตัวแรกเริ่มจาก 0 ถ้าไม่กำหนด end จะเอาตั้งแต่ตำแหน่ง start ไปจนถึงตัวสุดท้าย<br />
&nbsp;</p>
<pre class="javascript:controls" name="code">
// ตัวอย่างการใช้งาน
var cars=[&quot;Toyota&quot;,&quot;Honda&quot;,&quot;Isuzu&quot;,&quot;Mitsubishi&quot;];  // ตัวแปร array

// กรณีดึงตำแหน่ง ที่ 2 กับ 3 (&quot;Honda&quot;,&quot;Isuzu&quot;)
// แนวทางการกำหนด start และ end ถ้าต้องการตัวที่ 2 กับ 3
// กำหนด 2,3 แล้วลดค่าตัวแรกลง 1 ค่า จะได้ค่าที่ใช้กำหนดจริงเท่ากับ 1,3
var carsUseSlice=cars.slice(1,3); 
// จะได้ carsUseSlice=[&quot;Honda&quot;,&quot;Isuzu&quot;]

// กรณีดึงตำแหน่งที่ 2 ไปจนถึงตำแหน่งสุดท้าย ไมต้องกำหนด end กำหนด
var carsUseSlice=cars.slice(1); 
// จะได้ carsUseSlice=[&quot;Honda&quot;,&quot;Isuzu&quot;,&quot;Mitsubishi&quot;];

// กรณีดึงตำแหน่งเริ่มจาก 2 ตัวหลัง 
var carsUseSlice=cars.slice(-2); 
// จะได้ carsUseSlice=[&quot;Isuzu&quot;,&quot;Mitsubishi&quot;];</pre>
<p>&nbsp;</p>]]></description><pubDate>Tue, 21 Sep 2010 03:02:34 +0700</pubDate></item><item><title>ทบทวนการ สร้าง และใช้งาน ตัวแปร array ใน javascript</title><link>http://www.ninenik.com/ทบทวนการ_สร้าง_และใช้งาน_ตัวแปร_array_ใน_javascript-341.html</link><description><![CDATA[<p>ตัวแปร array ใช้สำหรับเก็บค่าหลายค่า ไว้ในตัวแปรเดียว ตัวอย่าง<br />
&nbsp;</p>
<pre class="php:controls" name="code">
// กำหนดตัวแปรสำหรับแต่ละตัว กรณีไม่ได้กำหนดเป็น แบบ array
var cars1=&quot;Toyota&quot;;
var cars2=&quot;Honda&quot;;
var cars3=&quot;Isuzu&quot;;</pre>
<p>ถ้าเราต้องการเก็บรายการ brand ของรถยนต์แต่ละคัน เป็นตัวแปร array สามารถกำหนดได้ 3 รูปแบบ ต่อไปนี้<br />
<br />
&nbsp;</p>
<pre class="javascript:controls" name="code">
// การกำหนดแบบ array แบบที่ 1 กรณีทั่วไป
var cars=new Array(3); // 3 คือจำนวนค่าที่ต้องการกำหนด ในที่นี้ 3 รายการ
cars[0]=&quot;Toyota&quot;;
cars[1]=&quot;Honda&quot;;
cars[2]=&quot;Isuzu&quot;;</pre>
<pre class="javascript:controls" name="code">
// การกำหนดแบบ array แบบที่ 2 กรณีการกำหนดแบบย่อ
var cars=new Array(&quot;Toyota&quot;,&quot;Honda&quot;,&quot;Isuzu&quot;);</pre>
<pre class="javascript:controls" name="code">
// การกำหนดแบบ array แบบที่ 3
var cars=[&quot;Toyota&quot;,&quot;Honda&quot;,&quot;Isuzu&quot;];</pre>
<p>* กรณีเรากำหนดค่าภายในตัวแปรเป็นตัวเลข หรือ true/false&nbsp; ชนิดของตัวแปรที่ได้จะเป็น ตัวเลย number หรือ <br />
boolean โดยจะไม่เป็น ตัวแปรประเภท String<br />
&nbsp;</p>
<p>การเรียกใช้งาน<br />
สามารถใช้งานตัวแปร array ดังนี้<br />
&nbsp;</p>
<pre class="javascript:controls" name="code">
alert(cars[0]); // ตัวแปร array cars ตัวแรก ค่าที่ได้ คือ Toyota โดย index เริ่มต้นที่เลข 0 
alert(cars[1]) // ตัวแปร array cars ตัวที่สอง ค่าที่ได้ คือ Honda โดย index เท่ากับ 1 
....... เป็นต้น.........</pre>
<p>การกำหนดค่าใหม่ หรือเปลี่ยนแปลงค่าตัวแปร array ที่สร้างมาแล้ว</p>
<p>สามารถกำหนดเข้าไปโดยตรง ตัวอย่าง<br />
ต้องการเปลี่ยนต่าตัวแปร array cars ตัวที่ 3 ค่าเดิมคือ Isuzu<br />
&nbsp;</p>
<pre class="javascript:controls" name="code">
cars[2]=&quot;Isuzu&quot;; // ค่าเดิม
// สามารถกำหนดค่าใหม่เข้าไปแทนที่ได้เลย เป็น
cars[2]=&quot;Mitsubishi&quot;; // กำหนดค่าใหม่
</pre>
<p>การหาจำนวน รายการทั้งหมดที่มีในตัวแปร array <br />
&nbsp;</p>
<pre class="javascript:controls" name="code">
alert(cars.length); // จำนวนรายการทั้งหมดในตัวแปร array ชื่อ cars มี 3 </pre>
<p>การกำหนดค่า จำนวนรายการทั้งหมดใน array<br />
&nbsp;</p>
<pre class="javascript:controls" name="code">
cars.length=4; // จากเดิมมี 3 เราสามารถกำหนดค่าเพิ่มเป็น 4 โดยค่าของรายการที่เพิ่ม จะเป็นค่าว่าง
// นั้นค่าจะได้ตัวแปร cars[3] มีค่าเท่ากับ ค่าว่าง</pre>
<p>&nbsp;</p>]]></description><pubDate>Mon, 20 Sep 2010 19:54:03 +0700</pubDate></item><item><title>เริ่มใช้ และ ประยุกต์ CKEditor ให้ใช้งานง่าย เต็มความสามารถ </title><link>http://www.ninenik.com/เริ่มใช้_และ_ประยุกต์_CKEditor_ให้ใช้งานง่าย_เต็มความสามารถ_-315.html</link><description><![CDATA[<p>ดูเหมือน CKEditor กำลังเป็นที่สนใจ และได้รับความนิยม สำหรับใครที่ต้องการใช้งาน คุณสมบัติที่ว่าดี ของ CKEditor มาใช้งาน ลองนำรูปแบบการใช้งาน ที่จะได้แนะนำต่อไป ไปใช้งาน อาจช่วยให้การใช้งาน CKEditor เป็นไปอย่างสะดวก</p>
<p>ดาวโหลด เวอร์ชันล่าสุดได้ที่ <a href="http://ckeditor.com/download">http://ckeditor.com/download</a> แตกไฟล์ แล้ว ก็อบปี้โฟลเดอร์ ckeditor ไว้ใช้งาน<br />
ตัวอย่าง<br />
<br />
&nbsp;</p>
<p><textarea id="editor1" name="editor1">&lt;p&gt;This is some &lt;strong&gt;sample text&lt;/strong&gt;.
You are using &lt;a href=&quot;http://ckeditor.com/&quot;&gt;CKEditor&lt;/a&gt;.&lt;/p&gt;
</textarea></p>
<p><script type="text/javascript" src="../ckeditor/ckeditor.js"></script><script type="text/javascript" src="demo/cke_config.js"></script><script type="text/javascript">
var editorObj=CKEDITOR.replace( 'editor1',cke_config); 
// editor1 ชื่อ id ของ textarea ที่ต้องการใช้งาน ckeditor
// var editorObj=CKEDITOR.replace( 'editor1',cke_config,dataValue);  // กรณีดึงข้อมูลมาแก้ไข
</script><br />
<button onclick="InsertHTML('&lt;p&gt;แทรก  HTML&lt;/p&gt;',editorObj);">แทรก HTML</button> &nbsp;<button onclick="SetContents('&lt;p&gt;แทนที่ข้อความทั้งหมด&lt;/p&gt;',editorObj);">แทนที่ข้อความทั้งหมด</button> &nbsp;<button onclick="alert(GetContents(editorObj));">แสดงข้อมูลใน CKEditor</button> <br />
</p>
<p>สร้างไฟล์ cke_config.js สำหรับไว้กำหนดคุณสมบัติของ CKEditor <a target="_blank" href="http://www.ninenik.com/note/ckeditor_toolbar_full.txt">&nbsp;(รูปแบบ Toolbar คลิก)</a> แทรกโค้ดามด้านล่าง<br />
<br />
&nbsp;</p>
<pre class="javascript:controls" name="code">
// JavaScript Document
var cke_config={
	skin:'kama', // kama | office2003 | v2
	language:'th', // th / en and more.....
	extraPlugins :'uicolor',// เรียกใช้ plugin ให้สามารถแสดง UIColor Toolbar ได้
	uiColor :'#9C3', // กำหนดสีของ ckeditor
	extraPlugins : 'autogrow', // เรียกใช้ plugin ให้สามารถขยายขนาดความสูงตามเนื้อหาข้อมูล
	autoGrow_maxHeight : 400,	 // กำหนดความสูงตามเนื้อหาสูงสุด ถ้าเนื้อหาสูงกว่า จะแสดง scrollbar
	enterMode: 2,// กดปุ่ม Enter -- 1=แทรกแท็ก &lt;p&gt; 2=แทรก &lt;br&gt; 3=แทรก &lt;div&gt;
	shiftEnterMode	:1,// กดปุ่ม Shift กับ Enter พร้อมกัน 1=แทรกแท็ก &lt;p&gt; 2=แทรก &lt;br&gt; 3=แทรก &lt;div&gt;
	height :200, // กำหนดความสูง
	width :800, // กำหนดความกว้าง * การกำหนดความกว้างต้องให้เหมาะสมกับจำนวนของ Toolbar
/*		fullPage : true, // กำหนดให้สามารถแก้ไขแบบเโค้ดเต็ม คือมีแท็กตั้งแต่ &lt;html&gt; ถึง &lt;/html&gt;*/
	toolbar : [
					['Source','-','Templates'],
					['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
					['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],
					['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
					['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak','UIColor']
				]
}

function InsertHTML(htmlValue,editorObj){// ฟังก์ขันสำหรับไว้แทรก HTML Code
	if(editorObj.mode=='wysiwyg'){
		editorObj.insertHtml(htmlValue);
	}else{
		alert( 'You must be on WYSIWYG mode!');
	}	
}
function SetContents(htmlValue,editorObj){ // ฟังก์ชันสำหรับแทนที่ข้อความทั้งหมด
	editorObj.setData(htmlValue);
}
function GetContents(editorObj){// ฟังก์ชันสำหรับดึงค่ามาใช้งาน
	return editorObj.getData();
}
function ExecuteCommand(commandName,editorObj){// ฟังก์ชันสำหรับเรียกใช้ คำสั่งใน CKEditor
	if(editorObj.mode=='wysiwyg'){
		editorObj.execCommand(commandName);
	}else{
		alert( 'You must be on WYSIWYG mode!');
	}
}
</pre>
<p>ฟังก์ฃัน InsertHTML สามารถประยุกต์ใช้งานกรณีใช้กับเว็บบอร์ด และมีการอ้างอิง ความคิดเห็น<br />
ฟังก์ชัน SetContents สามารถประยุกต์ใช้ Reset ค่าใน CKEditor ให้ว่างหรือล้างค่าได้<br />
ฟังก์ชัน GetContents สามารถประยุกต์ไว้สำหรับเช็คว่า CKEditor มีค่าว่าหรือไม่ก่อน Submit<br />
ฟังก์ชัน ExecuteCommand สามารถไว้ใช้งานเพิ่มเรียกใช้คำสั่ง ของ CKEditor จากภายนอก เช่น<br />
ExecuteCommand('link',editorObj) เป็นต้น</p>
<p>ตัวอย่าง การเรียกใช้งาน<br />
&nbsp;</p>
<pre class="xhtml:controls" name="code">
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;
 &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;

&lt;title&gt;&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;

&lt;p&gt;
&lt;textarea id=&quot;editor1&quot; name=&quot;editor1&quot;&gt;
&amp;lt;p&amp;gt;This is some &amp;lt;strong&amp;gt;sample text&amp;lt;/strong&amp;gt;. 
You are using &amp;lt;a href=&quot;http://ckeditor.com/&quot;&amp;gt;CKEditor&amp;lt;/a&amp;gt;.&amp;lt;/p&amp;gt;
&lt;/textarea&gt;
&lt;/p&gt;
 
&lt;script type=&quot;text/javascript&quot; src=&quot;ckeditor/ckeditor.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;cke_config.js&quot;&gt;&lt;/script&gt;		
&lt;script type=&quot;text/javascript&quot;&gt;
var editorObj=CKEDITOR.replace( 'editor1',cke_config); 
// editor1 ชื่อ id ของ textarea ที่ต้องการใช้งาน ckeditor
// var editorObj=CKEDITOR.replace( 'editor1',cke_config,dataValue);  // กรณีดึงข้อมูลมาแก้ไข
&lt;/script&gt;			
&lt;br /&gt;



&lt;button onclick=&quot;InsertHTML('&lt;p&gt;แทรก  HTML&lt;/p&gt;',editorObj);&quot;&gt;แทรก  HTML&lt;/button&gt;
&amp;nbsp;
&lt;button onclick=&quot;SetContents('&lt;p&gt;แทนที่ข้อความทั้งหมด&lt;/p&gt;',editorObj);&quot;&gt;แทนที่ข้อความทั้งหมด&lt;/button&gt;
&amp;nbsp;
&lt;button onclick=&quot;alert(GetContents(editorObj));&quot;&gt;แสดงข้อมูลใน CKEditor&lt;/button&gt;

&lt;/body&gt;
&lt;/html&gt;</pre>
<p>ส่วนการใช้งานกรณี ร่วมกับ การอัพโหลดไฟล์ ,&nbsp; jQuery และ Ajax จะนำเสนอในโอกาสต่อไป<br />
<span style="color: #ffcc00">* การอัพโหลดโดยใฃ้ CKfinder ดูจะใช้ได้ดี แต่ยังอยากใช้กับ filemanager ของ FCKeditor อยู่ รอก่อนว่า จะมีใครพัฒนาให้ filemanager ใช้งานกับ CKEditor</span></p>]]></description><pubDate>Sat, 21 Aug 2010 19:12:13 +0700</pubDate></item><item><title>การสร้าง popup ที่แตกต่าง ด้วยวิธี showModalDialog  </title><link>http://www.ninenik.com/การสร้าง_popup_ที่แตกต่าง_ด้วยวิธี_showModalDialog__-314.html</link><description><![CDATA[<p>การสร้าง หน้า window ใหม่ หรือ popup window ที่พิเศษ กว่า popup ที่ใช้ฟังก์ชัน window.open&nbsp; ด้วยการใช้วิธีที่เรียกว่า showModalDialog&nbsp; <br />
dialog หรือ popup ทีสร้างจากวิธีแบบ showModalDialog&nbsp; มีประโยชน์สำหรับการที่จะทำให้ผู้ใช้ให้ความสนใจต่อเนื้อหาในหน้าที่แสดง ซึ่งยังสามารถใช้แสดงข้อความที่มีความสำคัญที่ผู้ใช้ควรทำตามคำแนะนำหรือ ได้รับทราบเป็นข้อมูลไว้ ก่อนที่ดำเนินการอื่นๆ ต่อไป</p>
<p>ตัวอย่าง</p>
<p><button onclick="popupModal('demo/sample_data.php',500,200);">Sample Popup</button> <script type="text/javascript">
function popupModal(url,width,height){
	var myDate=new Date();
	var setUniqe=myDate.getTime(); // ใช้สำหรับ ป้องกันการ cache กรณีกำลังทดสอบ
	
	var diaxFeature="dialogWidth:"+width+"px;"
	+"dialogHeight:"+height+"px;"
/*	+"dialogLeft:"+width+"px;"
	+"dialogTop:"+width+"px;"		*/
	+"center:yes;"
	+"edge:raised;" // sunken | raised 
	+"resizable:no;"
	+"status:no;"
	+"scroll:no;";	
	window.showModalDialog(url+"?"+setUniqe,"", diaxFeature);
	// กรณีไม่ใช้ setUniqe
	//  window.showModalDialog(url,"", diaxFeature); 
}
</script></p>
<p><br />
วิธีสร้าง popup แบบ window.showModalDialog จะมีความคล้ายกับ วิธีการใช้งาน window.open คือการรับค่าชื่อไฟล์ หรือ url ที่ต้องการ แล้วเปิดเป็นหน้าต่างใหม่ <br />
ความแตกต่าง<br />
window.showModalDialog จะสร้างหน้าต่างใหม่เสมอ แม้ว่าบราวเซอร์จะกำหนดให้เปิดหน้าต่างใหม่แบบ Tab ส่วน window.open จะขึ้นอยู่กับการตั้งค่าของ บราวเซอร์<br />
และข้อแตกต่างที่สำคัญ คือ ผู้ใช้ต้องทำการปิด popup นั้นลงก่อน จึงจะใช้งานหน้าเว็บที่เปิด popup นั้นขึ้นมาได้ เป็นการโฟกัสผู้ใช้ไปยัง popup นั้นไปในตัว<br />
<br />
การวิธีการข้างต้นผู้ใช้ยังสามารถใช้งานหน้าต่างอื่น หรือโปรแกรมอื่นได้ตามปกติ <br />
&nbsp;</p>
<p><br />
ตัวอย่างโค้ด&nbsp; (ทดสอบทำงานได้ดีใน IE และ Firefox ส่วนบราวเซอร์อื่น ทำงานคล้าย window.open)<br />
<br />
&nbsp;</p>
<pre class="javascript:controls" name="code">
&lt;button onclick=&quot;popupModal('sample_data.php',500,200);&quot;&gt;Sample Popup&lt;/button&gt;

&lt;script type=&quot;text/javascript&quot;&gt;
function popupModal(url,width,height){
	var myDate=new Date();
	var setUniqe=myDate.getTime(); // ใช้สำหรับ ป้องกันการ cache กรณีกำลังทดสอบ
	
	var diaxFeature=&quot;dialogWidth:&quot;+width+&quot;px;&quot;
	+&quot;dialogHeight:&quot;+height+&quot;px;&quot;
/*	+&quot;dialogLeft:&quot;+width+&quot;px;&quot;
	+&quot;dialogTop:&quot;+width+&quot;px;&quot;		*/
	+&quot;center:yes;&quot;
	+&quot;edge:raised;&quot; // sunken | raised 
	+&quot;resizable:no;&quot;
	+&quot;status:no;&quot;
	+&quot;scroll:no;&quot;;	
	window.showModalDialog(url+&quot;?&quot;+setUniqe,&quot;&quot;, diaxFeature);
	// กรณีไม่ใช้ setUniqe
	//  window.showModalDialog(url,&quot;&quot;, diaxFeature); 
}
&lt;/script&gt;</pre>
<p>&nbsp;</p>]]></description><pubDate>Fri, 20 Aug 2010 22:51:54 +0700</pubDate></item><item><title>javascript เรียกฟังก์ชัน ใน parent จาก iframe</title><link>http://www.ninenik.com/javascript_เรียกฟังก์ชัน_ใน_parent_จาก_iframe-305.html</link><description><![CDATA[<p>ทบทวนความรู้ การเรียกใช้งาน ฟังก์ชัน ใน parent จาก iframe&nbsp; ตัวอย่างต่อไปนี้ เป็น<br />
บันทึกช่วยจำ กรณีต้องการเรียกใช้งาน javascript ฟังก์ชัน ใน parent จาก iframe เงื่อนไข คือในไฟล์หลัก มี javascript ฟังก์ชัน อยู่ และมีการใช้งาน iframe โดยต้องการเรียกใช้งาน ฟังก์ชัน ในไฟล์หลัก จากไฟล์ iframe สามารถเป็นแนวทางได้ดังนี้<br />
<br />
&nbsp;</p>
<pre class="javascript:controls" name="code">
parent.callMe();
// parent.ชื่อฟังก์ชันที่เรียกใช้งาน
// parent.callMe();</pre>
<p>ตัวอย่างการใช้งานจากไฟล์ใน iframe<br />
&nbsp;</p>
<pre class="php:controls" name="code">
&lt;button type=&quot;button&quot; onclick=&quot;parent.callMe();&quot;&gt;คลิกเพื่อเรียกฟังก์ชัน callMe() จากไฟล์ iframe&lt;/button&gt;</pre>
<p>หรือ<br />
&nbsp;</p>
<pre class="javascript:controls" name="code">
&lt;script type=&quot;text/javascript&quot;&gt;
parent.callMe();
&lt;/script&gt;</pre>
<p>ตัวอย่างโค้ดไฟล์หลัก main_file_with_iframe.php<br />
&nbsp;</p>
<pre class="xhtml:controls" name="code">
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;
 &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
&lt;title&gt;คือในไฟล์หลัก มี javascript ฟังก์ชัน อยู่ และมีการใช้งาน ifram&lt;/title&gt;
&lt;style type=&quot;text/css&quot;&gt;
body {
	background-color: #333;
}
&lt;/style&gt;
&lt;/head&gt;

&lt;body&gt;

&lt;button type=&quot;button&quot; onclick=&quot;callMe();&quot;&gt;คลิกเพื่อเรียกฟังก์ชัน callMe() จากไฟล์หลัก&lt;/button&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;iframe name=&quot;myiframe&quot; src=&quot;my_iframe.php&quot; width=&quot;450&quot; height=&quot;350&quot; frameborder=&quot;1&quot;&gt;
&lt;/iframe&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
function callMe(){
	alert(&quot;Test&quot;);	
}
&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<p>ตัวอย่างโค้ดไฟล์ iframe&nbsp;&nbsp; my_iframe.php<br />
&nbsp;</p>
<pre class="xhtml:controls" name="code">
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;
 &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
&lt;title&gt;ฟังก์ชัน ในไฟล์หลัก จากไฟล์ iframe&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;


&lt;button type=&quot;button&quot; onclick=&quot;parent.callMe();&quot;&gt;คลิกเพื่อเรียกฟังก์ชัน callMe() จากไฟล์ iframe&lt;/button&gt;


&lt;/body&gt;
&lt;/html&gt;</pre>
<p>ตัวอย่าง<br />
<a href="http://www.ninenik.com/demo/main_file_with_iframe.php">http://www.ninenik.com/demo/main_file_with_iframe.php</a><br />
&nbsp;</p>]]></description><pubDate>Sat, 31 Jul 2010 21:15:47 +0700</pubDate></item><item><title>สั่ง print preview ใน IE และ ประยุกต์กับ บราวเซอร์ อื่น</title><link>http://www.ninenik.com/สั่ง_print_preview_ใน_IE_และ_ประยุกต์กับ_บราวเซอร์_อื่น-304.html</link><description><![CDATA[<p>ตัวอย่าง ต่อไปนี้เป็นโค้ดสำหรับการสั่ง print preview ซึ่งทำงานได้เฉพาะ IE เท่านั้น แต่เราสามารถประยุกต์<br />
เพิ่มเติม ตามตัวอย่างโค้ด ด้านล่าง สำหรับกรณี browser อื่นๆ</p>
<p>โค้ดตัวอย่าง<br />
&nbsp;</p>
<pre class="php:controls" name="code">
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; 
&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
&lt;title&gt;print preview&lt;/title&gt;

&lt;?php if($_GET['print_preview']==1){ ?&gt;
&lt;style type=&quot;text/css&quot; media=&quot;all&quot;&gt;
button#printPreview{
	display:none;	
}
body{
	padding:10px;	
}
&lt;/style&gt;
&lt;?php }else{ ?&gt;
&lt;style type=&quot;text/css&quot; media=&quot;print&quot;&gt;
button#printPreview{
	display:none;	
}
&lt;/style&gt;
&lt;?php } ?&gt;
&lt;/head&gt;

&lt;body&gt;

&lt;p&gt;ตัวอย่าง ต่อไปนี้เป็นโค้ดสำหรับการสั่ง print preview ซึ่งทำงานได้เฉพาะ IE เท่านั้น แต่เราสามารถประยุกต์&lt;br /&gt;
เพิ่มเติม ตามตัวอย่างโค้ด ด้านล่าง สำหรับกรณี browser อื่นๆ &lt;/p&gt;

&lt;script type=&quot;text/javascript&quot;&gt;
function printPreview() {
	if(navigator.appName == &quot;Microsoft Internet Explorer&quot;){
	if(!document._wb){
		var obj=&quot;&lt;object id='_wb' width='0' height='0' &quot;;
		obj+=&quot; classid='CLSID:8856F961-340A-11D0-A96B-00C04FD705A2'&gt;&lt;/object&gt;&quot;;
		document.body.insertAdjacentHTML(
			&quot;beforeEnd&quot;,obj
		); 
	}
	_wb.ExecWB(7,1)
	}else{
		var windowWidth=850;
		var windowHeight=550;
		var myleft=(screen.width)?(screen.width-windowWidth)*0.5:100;    
   		var mytop=(screen.height)?(screen.height-windowHeight)*0.5:100;
		var feature='left='+myleft+',top='+eval(mytop-50)+',width='+windowWidth+',height='+windowHeight+',';
		feature+='menubar=yes,status=no,location=no,toolbar=no,scrollbars=yes';
		window.open(window.location+'?print_preview=1','welcome',feature);
	}
}
&lt;/script&gt;

&lt;button id=&quot;printPreview&quot; onclick=&quot;printPreview()&quot;&gt;Print Preview&lt;/button&gt;

&lt;/body&gt;
&lt;/html&gt;</pre>
<p>ตัวอย่าง</p>
<p><a href="http://www.ninenik.com/demo/print_preview.php">http://www.ninenik.com/demo/print_preview.php</a><br />
<br />
อย่างไรก็ตาม IE ที่มีระบบ security สูงก็อาจไม่สามารถใช้งานได้ ให้ปรับฟังก์ชันเป็น</p>
<pre class="javascript:controls" name="code">
&lt;script type=&quot;text/javascript&quot;&gt;
function printPreview() {
		var windowWidth=850;
		var windowHeight=550;
		var myleft=(screen.width)?(screen.width-windowWidth)*0.5:100;    
   		var mytop=(screen.height)?(screen.height-windowHeight)*0.5:100;
		var feature='left='+myleft+',top='+eval(mytop-50)+',width='+windowWidth+',height='+windowHeight+',';
		feature+='menubar=yes,status=no,location=no,toolbar=no,scrollbars=yes';
		window.open(window.location+'?print_preview=1','welcome',feature);

}
&lt;/script&gt;</pre>
<p>เพื่อใฃ้ในรูปแบบธรรมดา และรองรับทุกบราวเซอร์ โดยสามารถกำหนดรูปแบบที่ต้องการแสดงเมื่อทำการพิมพ์<br />
ด้วยการเพิ่ม css style ในส่วนของ โค้ดตามตำแน่งด้านล่าง</p>
<pre class="php:controls" name="code">
&lt;?php if($_GET['print_preview']==1){// กำหนดรูปแบบการพิมพ์กรณี preview popup หน้าใหม่ ?&gt;
&lt;style type=&quot;text/css&quot; media=&quot;all&quot;&gt;
button#printPreview{
	display:none;	
}
body{
	padding:10px;	
}
&lt;/style&gt;
&lt;?php }else{ // กำหนดรูปแบบการพิมพ์กรณี preview ผ่าน บราวเซอร์ ?&gt;
&lt;style type=&quot;text/css&quot; media=&quot;print&quot;&gt;
button#printPreview{
	display:none;	
}
&lt;/style&gt;
&lt;?php } ?&gt;</pre>
<p>&nbsp;</p>
<p>&nbsp;</p>]]></description><pubDate>Thu, 29 Jul 2010 22:03:31 +0700</pubDate></item><item><title>ทบทวน วันที่ date object  ใน javascript </title><link>http://www.ninenik.com/ทบทวน_วันที่_date_object__ใน_javascript_-293.html</link><description><![CDATA[<p><strong>การดึงค่ามาใช้งาน<br />
</strong></p>
<pre class="javascript:controls" name="code">
var myDate=new Date(2010,6,1,17,30,30,500);
myDate.getFullYear() = 2010  
// แสดงปี ค.ศ. 4 หลัก

myDate.getYear() = 110  
// ไม่นิยมเพราะจะขึ้นกับ บราวเซอร์ ถ้าใน IE จะเท่ากับ 2010 ใน FF เท่ากับ 2010-1900

myDate.getMonth() = 6 
// เดือน 0-11

myDate.getDate() = 1 
// วันที่ 1-31

myDate.getDay() = 4 
// วัน 0=Sunday, 1=Monday

myDate.getHours() = 17 
// ชั่วโมง 0-23

myDate.getMinutes() = 30 
// นาที 0-59

myDate.getSeconds() = 30  
// วินาที 0-59

myDate.getMilliseconds() = 500  
// มิลลิวินาที 0-999

myDate.getTime() = 1277980230500
// เวลาทั้งหมด เป็น มิลลิวินาที ได้จาก เวลา timestamp + millisecond , 1277980230 + 500

myDate.getTimezoneOffset() = -420
// ความต่างของเวลามาตรฐานโลกตามนาฬิกาที่กรีนิช ในอังกฤษ (คำย่อคือ GMT) กับเวลาที่บ้านเรา
// หน่วยเป็น นาที จากตัวอย่าง -420 ได้จาก 60 นาที คูณด้วย 7 ชม.
// ค่าติดลลบแสดงว่าเร็วกว่าเวลาที่ ที่กรีนิช ในอังกฤษ   420/60 =7 ชม.

myDate.getUTCFullYear() = 2010
// แสดงปี ค.ศ. 4 หลัก ที่กรีนิช ในอังกฤษ

myDate.getUTCMonth() = 6
// เดือน 0-11 ที่กรีนิช ในอังกฤษ

myDate.getUTCDate() = 1
// วันที่ 1-31 ที่กรีนิช ในอังกฤษ

myDate.getUTCDay() = 4
// วัน 0=Sunday, 1=Monday ที่กรีนิช ในอังกฤษ

myDate.getUTCHours() = 10
// ชั่วโมง 0-23 ที่กรีนิช ในอังกฤษ

myDate.getUTCMinutes() = 30
// นาที 0-59 ที่กรีนิช ในอังกฤษ

myDate.getUTCSeconds() = 30
// วินาที 0-59 ที่กรีนิช ในอังกฤษ

myDate.getUTCMilliseconds() = 500
// มิลลิวินาที 0-999 ที่กรีนิช ในอังกฤษ</pre>
<p><strong>การแปลงค่า<br />
</strong></p>
<pre class="javascript:controls" name="code">
myDate.toGMTString() = Thu, 01 Jul 2010 10:30:30 GMT
// แปลงวันที่เป็นเวลาที่กรีนิช ในอังกฤษ เป็นแบบข้อความ

myDate.toLocaleString() = Thursday, July 01, 2010 5:30:30 PM
// แปลงวันที่เป็นเวลาที่บ้านเรา

myDate.toLocaleDateString() = Thursday, July 01, 2010
// แปลงวันที่เป็นเวลาที่บ้านเรา ไม่เอาเวลา

myDate.toLocaleTimeString() = 5:30:30 PM
// แปลงวันที่เป็นเวลาที่บ้านเรา ไม่เอาวันที่

myDate.toString() = Thu Jul 01 2010 17:30:30 GMT+0700 (SE Asia Standard Time)
// แปลงวันที่เป็นเวลาที่บ้านเรา เป็นแบบ universal time

myDate.toUTCString() = Thu, 01 Jul 2010 10:30:30 GMT
// แปลงวันที่เป็นเวลาที่กรีนิช ในอังกฤษ เป็นแบบข้อความ

myDate.valueOf() = 1277980230500
// แปลงวันที่เป็นเวลาในหน่วย มิลลิวินาที ได้จาก เวลา timestamp + millisecond , 1277980230 + 500</pre>
<p><strong>การตั้งค่าเวลา<br />
</strong></p>
<pre class="javascript:controls" name="code">
// สำหรับการตั้งค่าจะใช้คำสั่งคล้ายกับคำสั่งในการดึงค่ามาใช้ แต่เปลี่บนจาก get เป็น set และเพิ่มค่าพารามิเตอร์เข้าไปในวงเล็บ
// เช่น
myDate.getFullYear()
// เป็น
myDate.setFullYear(2010,6,1)

// หรือ
myDate.getHours()
// เป็น
myDate.setHours(17,30,30,500)</pre>
<p>&nbsp;</p>]]></description><pubDate>Mon, 05 Jul 2010 11:21:07 +0700</pubDate></item><item><title>สร้าง comment ด้วย social plugins ใน facebook api อย่างง่ายดาย</title><link>http://www.ninenik.com/สร้าง_comment_ด้วย_social_plugins_ใน_facebook_api_อย่างง่ายดาย-291.html</link><description><![CDATA[<p>ดูตัวอย่าง และทดสอบการใช้ตามลิ้งค์ด้านล่าง<br />
<a href="http://developers.facebook.com/docs/reference/plugins/comments">http://developers.facebook.com/docs/reference/plugins/comments</a></p>
<p>ใครที่ต้องการสร้างระบบ comment หรือการแสดงความคิดเห็นในเว็บไซต์ของตัวเอง โดยไม่ต้องสร้างฐานข้อมูล สามารถเข้าไปใช้บริการ facebook api ที่ชื่อ comment ตามขั้นตอนต่อไปนี้</p>
<p>1.ล็อกอินเข้าสู่ระบบ facebook ปกติ ถ้ายังไม่ได้เป็นสมาชิก <br />
<a href="http://www.facebook.com/login.php">http://www.facebook.com/login.php</a><br />
ต้องทำการสมัครสมาชิก facebook ก่อนถึงจะใช้งานได้</p>
<p>2.เข้าไปที่หน้า <a href="http://developers.facebook.com/setup/">http://developers.facebook.com/setup/</a><br />
<img style="width: 284px; height: 207px" alt="" src="/userfiles/fb01.jpg" /></p>
<p>กรอกรายละเอียดดังนี้<br />
site name:--- กรอกเป็นชื่อ domain ตัวอย่าง ninenik<br />
site url:------&nbsp; กรอก <a href="http://www.youdomain.com/">http://www.youdomain.com/</a>&nbsp; ตัวอย่าง&nbsp; <a href="http://www.ninenik.com/">http://www.ninenik.com/</a><br />
ควรกรอก / หลังชื่อโดเมนปัองกันปัญหา การแจ้งเตือน Invalid url <br />
locale:-------&nbsp; เลือกภาษาไทย หรือภาษาอื่นตามต้องการ<br />
<br />
3.คลิกปุ่ม Create Application ถ้าไม่เกิดข้อผิดพลาด ระบบจะสร้าง Application&nbsp; ซึ่งมีรายละเอียด<br />
ดังรูปด้านล่าง ให้ทำการบันทึก ข้อมูลไว้ใช้งาน โดยเฉพาะ app id และ app secret<br />
<img width="355" height="135" alt="" src="/userfiles/fb02.jpg" /><br />
<br />
4.แทนที่ แท็กเปิด &lt;html ...&nbsp; ในไฟล์ที่ต้องการ แสดง comment ด้วย<br />
&nbsp;</p>
<pre class="xhtml:controls" name="code">
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;
      xmlns:fb=&quot;http://www.facebook.com/2008/fbml&quot;&gt;</pre>
<p>แทนที่ตำแหน่งตรงแถบสีฟ้าอ่อน ตามรูปด้านล่าง<br />
<img width="375" height="315" alt="" src="/userfiles/fb03.jpg" /><br />
<br />
5.แทรกโค้ด comment ด้านล่างในไฟล์ตามข้อ 4. ในตำแหน่งที่ต้องการแสดง<br />
&nbsp;</p>
<pre class="xhtml:controls" name="code">
&lt;fb:comments numposts=&quot;10&quot;  width=&quot;800&quot;&gt;&lt;/fb:comments&gt;
&lt;div id=&quot;fb-root&quot;&gt;&lt;/div&gt;
    &lt;script&gt;
      window.fbAsyncInit = function() {
        FB.init({appId: 'ใส่หมายเลข app id ตรงนี้', status: true, cookie: true,
                 xfbml: true});
      };
      (function() {
        var e = document.createElement('script');
        e.type = 'text/javascript';
        e.src = document.location.protocol +
          '//connect.facebook.net/th_TH/all.js';
        e.async = true;
        document.getElementById('fb-root').appendChild(e);
      }());
    &lt;/script&gt;</pre>
<p>6.ปรับแต่งคุณสมบัติของ comment ตามต้องการเช่น<br />
กำหนดความกว้าง<br />
width=&quot;800&quot;&nbsp; <br />
&nbsp;</p>
<pre class="xhtml:controls" name="code">
&lt;fb:comments width=&quot;800&quot;&gt;&lt;/fb:comments&gt;</pre>
<p>กำหนดจำนวนแถวความคิดเห็นที่แสดง<br />
numposts=&quot;10&quot;&nbsp; <br />
&nbsp;</p>
<pre class="xhtml:controls" name="code">
&lt;fb:comments numposts=&quot;10&quot;  width=&quot;800&quot;&gt;&lt;/fb:comments&gt;</pre>
<p><font face="Courier New">กำหนด uniqe id กรณีใฃ้ mod rewrite และไม่สามารถโพสข้อความได้ <br />
จำเป็นต้องกำหนด uniqe id โดยใช้ php เข้ารหัส ด้วยคำสั่ง</font></p>
<pre class="php:controls" name="code">
&lt;?=md5($_SERVER[&quot;SERVER_NAME&quot;].$_SERVER[&quot;REQUEST_URI&quot;])?&gt;</pre>
<p>ตัวอย่างผลลัพธ์ที่ได้ xid=&quot;91b95134d257f54425eb38b73d3df4b7&quot; <br />
&nbsp;</p>
<pre class="php:controls" name="code">
&lt;fb:comments xid=&quot;&lt;?=md5($_SERVER[&quot;SERVER_NAME&quot;].$_SERVER[&quot;REQUEST_URI&quot;])?&gt;&quot;   numposts=&quot;10&quot;  width=&quot;800&quot;&gt;&lt;/fb:comments&gt;</pre>
<p><span style="color: #ff0000">บรรทัดข้างล่างเป็นส่วน เพิ่มเติม แต่ไม่จำเป็น</span><br />
นอกจากนี้ยังสามารถกำหนด meta tags ในส่วนของ &lt;header&gt; เพื่อให้ facebook นำค่าไปใช้งาน ตัวอย่าง<br />
&nbsp;</p>
<pre class="xhtml:controls" name="code">
&lt;meta property=&quot;og:title&quot; content=&quot;รู้จักกับ Ajax Events ใน jQuery&quot;/&gt;
&lt;meta property=&quot;og:site_name&quot; content=&quot;ninenik.com&quot;/&gt;
&lt;meta property=&quot;og:image&quot; content=&quot;http://www.ninenik.com/mages/logo_01_Sat.gif&quot;/&gt;</pre>
<p>og:title ใช้กำหนดไดเติลที่ต้องการนำไปใฃ้ใน facebook ปกติ facebook จะดึงจาก tag title<br />
og:site_name ใช้กำหนด ชื่อเว็บไซต์<br />
og:image ใฃ้กำหนดรูปภาพ ปกติ facebook จะดึงจากรูปใน tag img ที่แสดงหน้านั้น</p>
<p>og:title ถ้าใช้ php สามารถดึงจากฐานข้อมูล หรือตัวแปรมาแสดง ตัวอย่าง<br />
&nbsp;</p>
<pre class="php:controls" name="code">
&lt;meta property=&quot;og:title&quot; content=&quot;&lt;?=$yourtitle?&gt;&quot;/&gt;</pre>
<p>&nbsp;</p>]]></description><pubDate>Sat, 19 Jun 2010 01:40:15 +0700</pubDate></item><item><title>การหา ขนาด ความกว้าง ความสูงของ รูปภาพ ด้วย javascript</title><link>http://www.ninenik.com/การหา_ขนาด_ความกว้าง_ความสูงของ_รูปภาพ_ด้วย_javascript-287.html</link><description><![CDATA[<p>ปกติเราสามารถหาขนาดความกว้าง ความสูง ของรูปภาพที่แสดงอยู่ด้วย javascript ได้โดยง่าย ดังนี้<br />
<strong>ตัวอย่าง HTML Code</strong><br />
&nbsp;</p>
<pre class="xhtml:controls" name="code">
&lt;img id=&quot;myimg&quot; src=&quot;http://www.ninenik.com/images/logo_01_Wed.gif&quot; /&gt;</pre>
<p><strong>Javascript&nbsp;Code</strong><br />
&nbsp;</p>
<pre class="javascript:controls" name="code">
&lt;script type=&quot;text/javascript&quot;&gt;
var jsimg=document.getElementById('myimg');
var jsimg_width=jsimg.width; // หาความกว้าง
var jsimg_height=jsimg.height; // หาความสูง
var jsimg_fileSize=jsimg.fileSize; // หาขนาดไฟล์ กรณ๊ IE เท่านั้น
&lt;/script&gt;</pre>
<p>ข้างต้นเป็นกรณีที่ไฟล์ รูปภาพนั้นแสดงแล้ว ส่วนกรณี หา ความกว้าง ความสูง ของรูปภาพ กรณีที่ยังไม่แสดง หรือทราบเฉพาะ url ของรูปภาพ สามารถทำได้ดังนี้<br />
&nbsp;</p>
<pre class="javascript:controls" name="code">
&lt;script type=&quot;text/javascript&quot;&gt;
var img_new=new Image();
img_new.src=&quot;http://www.ninenik.com/images/logo_01_Wed.gif&quot;;
img_new.onload=function(){
   var jsimg_width=img_new.width; // หาความกว้าง
   var jsimg_height=img_new.height; // หาความสูง
   var jsimg_fileSize=img_new.fileSize; // หาขนาดไฟล์ กรณ๊ IE เท่านั้น
}
&lt;/script&gt;</pre>
<p>&nbsp;</p>]]></description><pubDate>Wed, 02 Jun 2010 11:58:26 +0700</pubDate></item></channel></rss>
