Jump to: navigation, Search
Poakpong.com ปกป้อง ดอมคอม Life is random

หาความกว้างหน้าจอด้วย javascript แล้วส่งให้ php ทำงานต่อ

ต้องการหาขนาดความกว้างหน้าจอของคนที่เปิดดูเว็บไซต์ ค้นหาจาก google พบคำสั่ง javascript ในการตรวจหาความกว้างและความสูง แต่ที่ผมอยากได้คือให้นำค่าที่ได้ไปใช้งานต่อได้ใน php อีกทอดหนึ่ง

@FordAntiTrust แนะนำว่าให้ส่งค่าผ่านทาง Cookies (ยิ่งงงเข้าไปอีก ฮาา)

ค้นหาอีกรอบได้คำสั่งมาดังนี้ :

ชุดแรกใส่ใน <head> ทำการสร้าง cookies ขึ้นมาแล้วส่งไปยังหน้าที่เราใช้งาน (ก็คือหน้าที่เราต้องการใช้งานนั่นแหละ)

<?php
if(isset($HTTP_COOKIE_VARS["users_resolution"]))
$screen_res = $HTTP_COOKIE_VARS["users_resolution"];
else //means cookie is not found set it using Javascript
{
?>

<script language="javascript">
<!--
writeCookie();
function writeCookie()
{
var the_cookie = "users_resolution="+ screen.width;
document.cookie=the_cookie
location = 'document.php';
}
//-->
</script>

<?php
}
?>


ในส่วน <body> ก็ echo php ตามปกติ

<?php
echo "Your screen resolution is ". $screen_res;
?>


reference: Find Screen Resolution With PHP | PHP Magic Book

ปล.ใครมีวิธีง่ายกว่านี้ ช่วยแนะนำด้วยครับ :-)

Poakpong's Blog | 5 Comments

To support Thai language in iPod.

Inside Poakpong.com
มีอะไรใน ปกป้อง ดอทคอม

Subscribe RSS Feed

Recent All Posts

Poakpong's Playground

Copyright Notice

POAKPONG.com,
Update to 2008.

Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 License.

Disclaimer

เนื้อหา ข้อความ ความเชื่อ ในเว็บไซต์นี้ เป็นความคิดเห็นของผู้เขียน ผู้อ่านโปรดใช้วิจารณญาณในการอ่าน และคิดหาเหตุผลเพิ่มเติมด้วยตัวเอง รวมทั้งรูปภาพ ภาษา ซึ่งอาจไม่ถูกต้องตามหลักภาษา ผู้อ่านต้องใช้วิจารณญาณเช่นกัน

Our Network:

Create in Mac OS X

Search in Poakpong
ค้นหาใน ปกป้อง ดอทคอม



Advertising

เปิดเนต เปิดใจ
ปกป้องเสรีภาพของเรา
บนอินเทอร์เน็ตของเรา
(ร่วมลงชื่อในแถลงการณ์)

Google Friend Connect

Web Links

SEO Stats powered by MyPagerank.Net