1

如果浏览器中没有启用 javascript,我试图显示一条消息,然后我不想继续加载页面。我使用 php 所以我做了

<?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,我应该继续......

4

3 回答 3

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;
}
于 2013-04-18T07:23:59.963 回答
0

使用<noscript>标签 -

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

你也可以试试这个

if(isset($_GET['nojs']) && !isset($_SESSION['no_script']))
{
    $_SESSION['no_script'] = true; //Or cookie
}
于 2013-04-18T07:15:43.403 回答
0

您可以使用重定向,因此您可以将用户发送到一个页面,其中包含一条消息,例如如果禁用 JAVASCRIPT,您将无法访问该站点。

 <noscript>
 <meta http-equiv="refresh" content="0; url=http://www.yourdomain.com/nojsmessage.php" />
  </noscript>
于 2013-04-18T07:15:49.810 回答