<?php
echo "<script language="javascript">";
if(!isset($_GET['enable_js']) and $_GET['enable_js']!=1){
echo "window.location='?enable_js=1';";
}
echo "</script>";
?>
<?php
if($_GET['enable_js']==1){
echo "javascript is enabled";
}else{
echo "javascript is not enabled";
}
?>
สามารถนำไปประยุกต์ใช้ ร่วมกับ iframe ผ่าน ตัวแปร session ได้ดังนี้
ไฟล์ index.php
<?php session_start(); ?> <html> <head> <title></title> </head> <body> <iframe name="check_js" src="check_js.php" width="1" height="0" frameborder="0"> </iframe> <?php echo $_SESSION['ses_js_enable']; ?> </body> </html>
ไฟล์ check_js.php
<?php
session_start();
echo "<script language="javascript">";
if(!isset($_GET['enable_js']) and $_GET['enable_js']!=1){
echo "top.check_js.location='check_js.php?enable_js=1';";
}
echo "</script>";
?>
<?php
if($_GET['enable_js']==1){
$_SESSION['ses_js_enable']="javascript is enabled";
}else{
$_SESSION['ses_js_enable']="javascript is not enabled";
}
?>