자바 스크립트는 클라이언트 측에서 실행되는 DOM로드 (브라우저)에서 PHP는 서버 측에서 실행됩니다 (페이지가 브라우저로 전송되기 전에). 따라서 PHP는 브라우저가 자바 스크립트를 가지고 있는지 없는지 알지 못합니다.
가장 간단한 해결책은/보여주기 위해 자바 스크립트 자체를 사용하므로 같은 브라우저 내에서 다양한 요소를 숨기는 것입니다 :
<!doctype html>
<html>
<head>
<title>Test Page</title>
<style>
.showWithJS {
display:none;
}
</style>
</head>
<body>
<div class="showWithJS">
This DIV, and anything with the class "showWithJS",
will only be seen when Javascript is enabled.
</div>
<div class="hideWithJS">
This DIV, and anything with the class "hideWithJS",
will not be seen when Javascript is enabled.
</div>
<script src="http://code.jquery.com/jquery.min.js"></script>
<script>
$(document).ready(function(){
$('.showWithJS').show();
$('.hideWithJS').hide();
});
</script>
</body>
</html>
또 다른 옵션은 PHP 읽을 수있는 쿠키를 (설정하는 자바 스크립트를 사용하는 것) 자바 스크립트가 실행 중인지 여부를 나타냅니다. 그 단점은 물론 사용자가 자바 스크립트를 온/오프 중반 방문하면 쿠키가 해당 변경 사항을 반영하여 업데이트되지 않는다는 것입니다.
<?php
$javascriptOn = (isset($_COOKIE['javascript']) && $_COOKIE['javascript']=='on');
?><!doctype html>
<html>
<head>
<title>Test Page</title>
</head>
<body>
<?php if($javascriptOn){ ?>
<div>
This DIV will only be seen when Javascript is enabled.
</div>
<?php } ?>
<?php if(!$javascriptOn){ ?>
<div>
This DIV will not be seen when Javascript is enabled.
</div>
<?php } ?>
<script>
document.cookie = 'javascript=on';
</script>
</body>
</html>
이의 단점은 당신이 변화를 볼 수있는 페이지를 새로 고침 할 필요가 있으므로, (이 설정하고 같은 pageload 읽을 수 없습니다) 쿠키를 설정하는 pageload을 필요로한다는 것입니다.
PHP가 서버에서 실행된다는 것을 알고 있습니까? 그래서 그것 주위의 모든 HTML 태그에 상관하지 않습니다. – ThiefMaster