방문자의 모니터 해상도를 변수에 담을 순 없을까요?

방문자의 모니터 해상도를 변수에 담을 순 없을까요?

QA

방문자의 모니터 해상도를 변수에 담을 순 없을까요?

본문


<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var xy = navigator.appVersion;
xz = xy.substring(0,4);
document.write("<center><table border=1 cellpadding=2><tr><td>");
document.write("<center><b>", navigator.appName,"</b>");
document.write("</td></tr><tr><td>");
document.write("<center><table border=1 cellpadding=2><tr>");
document.write("<td>Code Name: </td><td><center>");
document.write("<b>", navigator.appCodeName,"</td></tr>");
document.write("<tr><td>Version: </td><td><center>");
document.write("<b>",xz,"</td></tr>");
document.write("<tr><td>Platform: </td><td><center>");
document.write("<b>", navigator.platform,"</td></tr>");
document.write("<tr><td>Pages Viewed: </td><td><center>");
document.write("<b>", history.length," </td></tr>");
document.write("<tr><td>Java enabled: </td><td><center><b>");
if (navigator.javaEnabled()) document.write("sure is!</td></tr>");
else document.write("not today</td></tr>")
document.write("<tr><td>Screen Resolution: </td><td><center>");
document.write("<b>",screen.width," x ",screen.height,"</td></tr>");
document.write("</table></tr></td></table></center>");
// End -->
</script>

 

방문자의 모니터 해상도가 1920인지 1600인지 1280인지 기타 등등 해상도의 가로를 알고 싶습니다.

위의 소스 데로하면 제 컴의 해상도가 나오네요..

그런데 위의 소스 값 다 필요 없구요.. 그중에서 screen.width 만 필요합니다. (물론 지우면 될것이고요.)

이 해상도 넓이를 php 변수에 담아서 사용하고 싶은데요..

 

자바스크립트로 튀어나온 값을 php 변수에 담을 방법이 없을까요?

이 질문에 댓글 쓰기 :

답변 2



$(function() {
    $.post('some_script.php', { width: screen.width, height:screen.height }, function(json) {
        if(json.outcome == 'success') {
            // do something with the knowledge possibly?
        } else {
            alert('Unable to let PHP know what the screen resolution is!');
        }
    },'json');
});

php



<?php
// For instance, you can do something like this:
if(isset($_POST['width']) && isset($_POST['height'])) {
    $_SESSION['screen_width'] = $_POST['width'];
    $_SESSION['screen_height'] = $_POST['height'];
    echo json_encode(array('outcome'=>'success'));
} else {
    echo json_encode(array('outcome'=>'error','error'=>"Couldn't save dimension info"));
}
?>

php와 자바가 운영되는 곳이 달라서 안된다는 답변이 잇을줄알엇는데 이렇게 소스를 알려주셔서 대단히 감사드립니다.

함 적용해보겟습니다..

답변을 작성하시기 전에 로그인 해주세요.
전체 123,532 | RSS
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT