2014-12-19 2 views
0

나는 다음과 같은 몇 가지 스크립트가 있지만브라우저 너비가 PHP 인 경우 조건은 어떻게됩니까?

<?php 
$width = "<script>document.write(window.outerWidth);</script>"; 
$width2 = (int)$width; 
echo $width2; 
if ($width2 < 800) { ?> 
    bad 
<? } else { ?> 
    ok 
<? } ?> 

저를 도와주세요 작동하지 않습니다 MDC window.screen docs.

+0

http://stackoverflow.com/questions/1504459/getting-the-screen-resolution-using-php –

+0

PHP가 서버에서 실행되어 화면 너비를 사용할 수 없다면 자바 스크립트가 필요하거나 화면 크기, 미디어 쿼리 – atmd

답변

0

당신은 자바 스크립트 또한

var screenWidth = window.screen.width, 
    screenHeight = window.screen.height; 
You can then send it to the server via Ajax (with an XmlHttpRequest). 

참조 (http://stackoverflow.com/questions/4180134/how-to-get-users-screen-resolution-with-phphttp://stackoverflow.com/questions/1504459/getting-the-screen-resolution-using-php에서 가져온)가 필요합니다 ...

0

당신은 자바 스크립트와 PHP를 혼합했습니다.

<script>document.write(window.outerWidth);</script> 

해당 자바 스크립트는 PHP에서 실행할 수 없습니다.

브라우저 너비를 얻으려면 JavaScript를 작성하고 브라우저에 넣고 실행해야합니다. JavaScript는 AJAX/form post에 의해 크기를 서버에 보내야합니다.

관련 문제