2013-04-18 20 views
1

我試圖顯示一條消息,如果在瀏覽器中沒有啓用JavaScript,然後我想不再繼續加載頁面。即時通訊使用PHP的,所以我做了終止代碼,如果沒有找到javascript

<?php exit;?> 

在noscipt但儘管瀏覽器已啓用JavaScript的PHP代碼出口工程... 我使用的代碼是這樣的:

<noscript> 
     <div style="text-align:center; margin-top:15px; color:#f00; margin-bottom:10px;text-decoration: blink;"> 
      <h1> 
       Please enable javascript<br style="margin-bottom: 5px;"/> 
       <h3>Else the system will not work correctly.</h3> 
      </h1> 
     </div> 
     <div align="center"> 
      <div class="title" style="font:bold 18px arial">Enabling Javascript</div> 
      For: <strong>FireFox</strong> 
      Go To:<strong>Options > Content</strong><br/> and Check the Enable Javascript. 
      <br/>OR<br/> 
      Refer this link to enable javascript according to your browser<br/> 
      <a href="http://www.enable-javascript.com/">http://www.enable-javascript.com/</a> 
      <?php exit;?> 
     </div> 
    </noscript> 

我應該怎麼不進一步進行,如果JavaScript是沒有啓用,如果啓用JS應該繼續...

+1

PHP運行在服務器端,而''

回答

0

使用<noscript>標籤 -

<noscript>Your browser does not support JavaScript!</noscript> 

你也可以試試這個

if(isset($_GET['nojs']) && !isset($_SESSION['no_script'])) 
{ 
    $_SESSION['no_script'] = true; //Or cookie 
} 
0

您可以使用重定向,所以你發送用戶的一個頁面,就像對不起消息您不能訪問該網站,如果JavaScript被禁用。

<noscript> 
<meta http-equiv="refresh" content="0; url=http://www.yourdomain.com/nojsmessage.php" /> 
    </noscript> 
1

noscript當javascript被禁用時會執行塊,並用於顯示替代內容。

<noscript> 
    <b>You don't have javascript enabled.</b> 
</noscript> 

或者如果禁用javascript,您可以將用戶重定向到另一頁。

<!DOCTYPE html> 
<html lang="en"> 
    <head> 
     <noscript> 
      <meta http-equiv="refresh" content="0; /?javascript=no"> 
     </noscript> 
     <meta charset="UTF-8"/> 
     <title></title> 
    </head> 
</html> 

在你的PHP代碼,你可以檢查

if(isset($_GET['javascript']) && $_GET['javascript'] == 'no') 
{ 
    exit; 
} 
+0

我的問題的解決方案將是if語句,但它不能很好地工作......對此沒有任何迴應 – Robz 2013-04-18 08:05:44