在客户端设置cookie_检测Cookie和JavaScript的客户端浏览器设置

本文介绍了如何检测客户端浏览器是否接受HTTP cookie和运行JavaScript。大部分浏览器默认启用这两项功能,但了解客户端设置对于应用设计至关重要,例如购物车依赖cookie,而JavaScript影响用户体验。由于服务器无法主动获取客户端特性,所以检测过程需要考虑HTTP协议的无状态性质和事件顺序。文章提供了在Firefox中设置测试环境的步骤,以及利用PHP和HTML noscript标签来检测JavaScript支持的方法。
摘要由CSDN通过智能技术生成

在客户端设置cookie

Introduction and Prerequisites

简介和先决条件

This article describes methods for detecting whether a client browser accepts and returns HTTP cookies and whether the client browser runs JavaScript.  Most client browsers will, by default, be configured to use cookies and JavaScript, but some may not do that, and it may be important to your application design to be aware of these client-side factors as you build your web documents.  For example, most shopping carts rely on cookies to store a pointer to the contents of the cart.  If your client has cookies disabled, the shopping cart would not work.  Rather than simply fail, it would be a better design to be able to tell the client about the dependency.  Or you might have a gallery that used jQuery to provide an attractive client experience.  If you knew that JavaScript was disabled you would be able to adjust the gallery behavior. 

本文介绍了用于检测客户端浏览器是否接受并返回HTTP cookie以及客户端浏览器是否运行JavaScript的方法。 默认情况下,大多数客户端浏览器都将配置为使用Cookie和JavaScript,但有些可能不会这样做,并且在构建Web文档时要意识到这些客户端因素对于您的应用程序设计可能很重要。 例如,大多数购物车都依赖Cookie来存储指向购物车内容的指针。 如果您的客户禁用了Cookie,则购物车将无法使用。 与其说简单地失败,不如说是能够告诉客户有关依赖性的更好的设计。 或者您可能拥有使用jQuery来提供有吸引力的客户体验的画廊。 如果您知道禁用了JavaScript,则可以调整图库的行为。

These concepts seems like common sense in application design, but the client/server relationship has a structure that hinders this common sense approach.  The order of request and response events is an important principle.  All communication is initiated by the client.  The client makes a request, the server-side scripts run, and the server-side scripts are complete before the response is sent to the browser.  As a result, any of the characteristics of the client browser that are not part of the request are invisible to the server-side scripts that create HTML documents.  And the server is a response-only device.  It cannot initiate communication with the client.  How, then, can we "look over the wall" to discern what the client browser will do with the cookies and JavaScript that we might send?

这些概念在应用程序设计中似乎是常识,但是客户/服务器关系的结构阻碍了这种常识方法。 请求和响应事件的顺序是重要的原则。 所有通信均由客户端启动。 客户端发出请求 ,运行服务器端脚本,并且请求的客户端浏览器的任何特征对于创建HTML文档的服务器端脚本都是不可见的。 服务器是仅响应的设备。 它无法启动与客户端的通信。 那么,我们如何才能“窥视墙壁”以辨别客户端浏览器将如何处理我们可能发送的cookie和JavaScript?

In order to understand the logic of these processes, you need to understand the stateless nature of HTTP protocols, and the order of events in a client/server system.  There are two articles here at E-E that can help with the background knowledge you'll need as you read this article.  If you're not familiar with these concepts, please take a moment to read these articles, then come back to this one.

为了了解这些过程的逻辑,您需要了解HTTP协议的无状态性质以及客户端/服务器系统中事件的顺序。 EE上有两篇文章可以帮助您阅读本文时所需要的背景知识。 如果您不熟悉这些概念,请花一点时间阅读这些文章,然后再回到这篇文章。

HTTP Client/Server HTTP客户端/服务器 PHP Sessions PHP会话

Setting Up a Test Bed

设置测试台

Since we will want to be able to test our scripts, we will need a browser that can both accept and refuse cookies, and can enable and disable JavaScript.  We can make these settings in the Firefox browser.  At the time of this writing (November 2014), Firefox is currently at release 33+, and these instructions are applicable to a Windows version of that release.  Mozilla has a way of moving things around from release to release, and you may find in the future that the instructions are no longer directly applicable.  Nevertheless, the concepts will still be workable, and a Google search for these headlines will lead you to an implementation of the concepts.  Similar instructions for Internet Explorer and Google Chrome are included at the end of the article.

由于我们希望能够测试脚本,因此我们需要一个既可以接受也可以拒绝cookie并可以启用和禁用JavaScript的浏览器。 我们可以在Firefox浏览器中进行这些设置。 在撰写本文时(2014年11月),Firefox当前版本为33+,这些说明适用于该版本的Windows版本。 Mozilla提供了一种在各个发行版之间进行迁移的方法,您将来可能会发现这些说明不再直接适用。 尽管如此,这些概念仍然可以使用,并且通过Google搜索这些标题,您可以实现这些概念。 本文末尾包含了针对Internet Explorer和Google Chrome的类似说明。

Enabling and Disabling Cookies in Firefox

在Firefox中启用和禁用Cookies

The path for this process starts with the Firefox menu, hidden behind the three-bar menu button in the upper right of the browser window.  To enable cookies for your test, follow these steps:

此过程的路径从Firefox菜单开始,该菜单隐藏在浏览器窗口右上方的三栏菜单按钮后面。 要为您的测试

1. Click the three-bar menu button to reveal the menu

1.单击三栏菜单按钮以显示菜单

2. Click "Options"

2.点击“选项”

3. Click "Privacy"

3.点击“隐私”

4. Uncheck "Accept cookies from sites"

4.取消选中“接受来自站点的cookie”

5. Click "Exceptions"

5.点击“例外”

6. Type your base URL, for example, Experts-Exchange.com

6.键入您的基本URL,例如

7. Click "Allow for Session"

7.单击“允许会话”

8. Close / OK the menu windows

8.关闭/确定菜单窗口

To disable cookies, follow steps 1-5 above, then:

若要

6. Scroll down to find and highlight your base URL

6.向下滚动以查找并突出显示您的基本URL

7. Click "Remove Site"

7.单击“删除站点”

8. Close / OK the menu windows

8.关闭/确定菜单窗口

After you're finished testing you may want to go back to step 4 and restore your preferred settings.

完成测试后,您可能需要返回步骤4并还原您的首选设置。

Enabling and Disabling JavaScript in Firefox

在Firefox中启用和禁用JavaScript

1. In the browser address bar, instead of a URL, type about:config

1.在浏览器地址栏中,而不是URL中,键入

2. Dismiss any warning box that may appear

2.消除可能出现的任何警告框

3. Scroll down the very long list of configuration options to find "javascript.enabled"

3.向下滚动很长的配置选项列表,找到“ javascript.enabled”

4. Click to highlight that line

4.单击以突出显示该行

5. Right-click to reveal a dialog box

5.右键单击以显示一个对话框

6. Click "Toggle" to enable or disable JavaScript

6.单击“切换”以启用或禁用JavaScript

After you've finished testing you may want to repeat the process to enable JavaScript.

完成测试后,您可能需要重复此过程以启用JavaScript。

Testing for Cookies

测试Cookie

When a server sends a cookie to the client browser, the browser stores the cookie and returns the cookie with each subsequent HTTP request to the same URL.  This means that we must use a two-step process to first set and then detect a cookie.  We can accomplish both steps in a single script file, and we can package the two-step process into a one-line function call.  The function will return the client's IP address if cookies are in play, or boolean FALSE if not.

当服务器将cookie发送到客户端浏览器时,浏览器将存储cookie并将cookie和随后的每个HTTP请求返回到相同的URL。 这意味着我们必须使用两步过程来首先设置然后检测cookie。 我们可以在一个脚本文件中完成两个步骤,并且可以将两步过程打包到一个单行函数调用中。 如果正在播放cookie,该函数将返回客户端的IP地址;否则返回布尔值FALSE。

Our strategy uses the client IP address and a "digested" version of the browser name (HTTP_USER_AGENT) as part of a small temporary file name on our server.  If there is no cookie in the request, we write this file, set a cookie, and redirect the browser to our current URL.  This redirect will cause a new browser request that will reload the script.  Upon the reload, if the cookie is present in the request we know that the client is a well-behaved browser that will accept and return cookies.  If the cookie is not present, but the temporary file is present, then we know that the browser did not return the cookie.

我们的策略将客户端IP地址和浏览器名称的“摘要”版本(HTTP_USER_AGENT)用作服务器上小型临时文件名的一部分。 如果请求中没有cookie,我们将编写此文件,设置cookie,然后将浏览器重定向到我们当前的URL。 此重定向将导致一个新的浏览器请求,该请求将重新加载脚本。 重新加载后,如果请求中存在cookie,我们就会知道客户端是行为良好的浏览器,它将接受并返回cookie。 如果不存在Cookie,但存在临时文件,那么我们知道浏览器未返回Cookie。

This will be a dependable approach most of the time, since most of the time the client's IP address and browser will be unique and consistent for at least the duration of this (essentially instantaneous) pair of requests.  There may be edge cases where this approach might not work perfectly.  One example that comes to mind would be a setting where multiple client browsers share a single IP address.  If two identical browsers on the same IP address simultaneously visited the same same web page, and they had different settings for cookies, a race condition could ensue that might give a false indicator of the cookie status.

在大多数情况下,这将是一种可靠的方法,因为在大多数情况下,客户端的IP地址和浏览器至少在这对(基本上是瞬时的)请求对期间都是唯一且一致的。 在某些极端情况下,此方法可能无法完美工作。 我想到的一个例子是多个客户端浏览器共享一个IP地址的设置。 如果使用相同IP地址的两个相同的浏览器同时访问了相同的网页,并且它们具有不同的Cookie设置,则可能会导致竞争状态,从而可能会错误指示Cookie的状态。

<?php // demo/cookie_check.php
/**
 * This script tries to detect whether a browser is accepting and returning cookies
 */
error_reporting(E_ALL);

function browser_cookies()
{
    // SETTINGS SHOULD ALLOW FOR SIMULTANEOUS ACCESS FROM MANY CLIENTS
    $cookiename = 'cookie_check';
    $client_agt = !empty($_SERVER['HTTP_USER_AGENT']) ? md5($_SERVER['HTTP_USER_AGENT']) : 'unknown';
    $client_ipa = !empty($_SERVER['REMOTE_ADDR'])     ? $_SERVER['REMOTE_ADDR']          : '1.1.1.1';
    $state_file = "cookie_check.$client_agt.$client_ipa.txt";

    // IF THERE IS A COOKIE OUR WORK IS DONE
    $cookie_value = !empty($_COOKIE[$cookiename]) ? $_COOKIE[$cookiename] : FALSE;

    // IF THERE IS NO COOKIE
    if (!$cookie_value)
    {
        // AND IF THE STATEFUL FILE EXISTS
        if (file_exists($state_file))
        {
            $cookie_value = FALSE;
        }
        // BUT IF THE STATEFUL FILE HAS NOT BEEN CREATED
        else
        {
            // CREATE THE STATEFUL FILE AND TRY TO SET A COOKIE
            file_put_contents($state_file, $client_ipa);
            setcookie($cookiename, $client_ipa);

            // NOW FORCE A RELOAD OF THE WEB PAGE
    	    header('Location: ' . $_SERVER['REQUEST_URI']);
            exit;
        }
    }

    // TIDY UP AFTER OURSELVES AND RETURN THE IP ADDRESS OR FALSE
    @unlink($state_file);
    return $cookie_value;
}


// USE CASE
if ($ip_addr = browser_cookies())
{
    echo "THIS CLIENT ACCEPTS AND RETURNS COOKIES AT IP ADDRESS: $ip_addr";
}
else
{
    echo "THIS CLIENT DOES NOT USE COOKIES";
}

Testing for JavaScript with Cookies

使用Cookie测试JavaScript

Conceptually this is nearly identical to testing for cookies, but there is one important protocol difference.  When we want to set a cookie and redirect the client browser to reload the web page, we can do so entirely in PHP without creating any browser output.  But we can't run any JavaScript without writing the JavaScript code to the client browser.  This means that the PHP header() function is unusable, since HTTP headers must come first and be complete before any browser output.  To get around this, we can use the meta-refresh tag in place of the header("Location: ...") function call.

从概念上讲,这与测试cookie几乎相同,但是协议存在一个重要差异。 当我们想要header()函数不可用,因为HTTP标头必须首先出现,并且必须在浏览器输出之前完成。 为了解决这个问题,我们可以使用meta-refresh标签代替header(“ Location:...”)函数调用。

<?php // demo/javascript_check.php
/**
 * This script tries to detect whether a browser will run JavaScript
 */
error_reporting(E_ALL);

function browser_javascript()
{
    // SETTINGS SHOULD ALLOW FOR SIMULTANEOUS ACCESS FROM MANY CLIENTS
    $signalname = 'javascript';
    $client_agt = !empty($_SERVER['HTTP_USER_AGENT']) ? md5($_SERVER['HTTP_USER_AGENT']) : 'unknown';
    $client_ipa = !empty($_SERVER['REMOTE_ADDR'])     ? $_SERVER['REMOTE_ADDR']          : '1.1.1.1';
    $state_file = "javascript_check.$client_agt.$client_ipa.txt";

    // IF THERE IS A JAVASCRIPT SIGNAL IN THE COOKIE OUR WORK IS DONE
    $signal_value = !empty($_COOKIE[$signalname]) ? $_COOKIE[$signalname] : FALSE;

    // IF THERE IS NO JAVASCRIPT SIGNAL
    if (!$signal_value)
    {
        // PREPARE A JAVASCRIPT SETCOOKIE TEST
        $jstest = <<<EOJ
<script>
document.cookie = "$signalname=$client_ipa";
</script>
EOJ;

        // PREPARE A META-REFRESH TAG
        $request = $_SERVER['REQUEST_URI'];
        $refresh = <<<EOR
<meta http-equiv="refresh" content="0;URL='$request'" />
EOR;

        // IF THE STATE FILE EXISTS BUT THERE IS NO JAVASCRIPT SIGNAL
        if (file_exists($state_file))
        {
            $signal_value = FALSE;
        }
        // BUT IF THE STATEFUL FILE HAS NOT BEEN CREATED
        else
        {
            // CREATE THE STATEFUL FILE AND TRY TO SET A JAVASCRIPT COOKIE
            file_put_contents($state_file, $client_ipa);
            echo $jstest;

            // NOW FORCE A RELOAD OF THE WEB PAGE
      	    echo $refresh;
            exit;
        }
    }

    // TIDY UP AFTER OURSELVES AND RETURN THE IP ADDRESS OR FALSE
    @unlink($state_file);
    return $signal_value;
}


// USE CASE
if ($ip_addr = browser_javascript())
{
    echo "THIS CLIENT RUNS JAVASCRIPT AT IP ADDRESS: $ip_addr";
}
else
{
    echo "THIS CLIENT DOES NOT SUPPORT JS";
}
browser_javascript() function to test for JavaScript. 

Testing for JavaScript Without Using Cookies

在不使用Cookie的情况下测试JavaScript

There is an HTML noscript tag that can be helpful.  This tag is used to wrap parts of the document that are to be evaluated by the browser if JavaScript is turned off.  One of the common uses of the noscript tag is to tell the client that he's missing a part of the web experience.  Example:

有一个HTML noscript标记可能会有所帮助。 如果关闭了JavaScript,则此标签用于包装将由浏览器评估的文档部分。

<noscript>
   Your browsing experience will be much better with JavaScript enabled!
</noscript>

We can exploit the script and noscript tags to determine whether the client runs JavaScript.  Like the other methods used to test for cookies and JavaScript, we still need something in the HTTP request to tell us the status of the client browser.  In this example, we will add a single URL parameter to the end of the request string and redirect the browser to reload our script.  If JavaScript is turned off, the browser will run the noscript content, and our refreshed URL will include noJS.  Otherwise, the browser will run the script content, and our refreshed URL will include JS

我们可以利用内容,并且刷新后的URL将包含内容,并且刷新后的URL将包含

<?php // demo/javascript_check_nocookie.php
/**
 * This script tries to detect whether a browser will run JavaScript
 */
error_reporting(E_ALL);

function browser_javascript_nocookie()
{
    $client_ipa = !empty($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '1.1.1.1';

    // IS THERE A SIGNAL STRING?
    $nojs = isset($_GET['noJS']);
    $js   = isset($_GET['JS']);
    if ($nojs || $js)
    {
        if ($nojs) return FALSE;
        if ($js)   return $client_ipa;
    }
    else
    {
        // PREPARE META-REFRESH TAGS WITH AN EXTRA URL PARAMETER
        $requestjs = $_SERVER['REQUEST_URI'];
        $requestno = $_SERVER['REQUEST_URI'];
        if (strpos($_SERVER['REQUEST_URI'], '?'))
        {
            $requestjs .= "&JS";
            $requestno .= "&noJS";
        }
        else
        {
            $requestjs .= "?JS";
            $requestno .= "?noJS";
        }
        $refresh = <<<EOR
<noscript><meta http-equiv="refresh" content="0;URL='$requestno'" /></noscript>
<script>document.write("<meta http-equiv=\"refresh\" content=\"0;URL='$requestjs'\" />");</script>
EOR;

        // NOW FORCE A RELOAD OF THE WEB PAGE
        echo $refresh;
        exit;
    }
}


if ($ip_addr = browser_javascript_nocookie())
{
    echo "THIS CLIENT RUNS JAVASCRIPT AT IP ADDRESS: $ip_addr";
}
else
{
    echo "THIS CLIENT DOES NOT SUPPORT JS";
}

Potential Issues

潜在问题

Is this a "best practices" way of determining whether a browser supports JavaScript? It works, but I think there can be some arguments against it. When you rewrite the URL with JS or noJS appended, you're exposing a data element that your client should not have to think about. If your client bookmarks the URL after the rewrite, the bookmark will permanently reflect the JS or noJS setting that was in play at the time the bookmark was created. The function will rely on this setting rather than testing for JavaScript each time. 

这是确定浏览器是否支持JavaScript的“最佳实践”方式吗? 它有效,但是我认为可能有人对此表示反对。 当您重写带有

A Two-Step Redirect to Restore the Original URL

两步重定向以还原原始URL

A pair of signal files can be incorporated into this logic to keep the stateful information between requests. This will let us rewrite the URL twice.  The initial page load will be ignorant of the state of JavaScript; it will prepare two signal files -- one to indicate support for JavaScript and one to indicate no JavaScript support. The first URL rewrite will trigger the JS or noJS determination in the browser and the resulting request will tell the server about JavaScript support via the added URL parameter.  With this information, the server can remove the complementary signal file.  The second rewrite will remove the JS or noJS signal string from the end of the URL.  The server can rely on the existence of the remaining signal file to know whether the browser has support for JavaScript.  In practice, this causes a flash in the browser address bar, as the URL is rewritten.  You can install this script and run it to see the process in action.

可以将一对信号文件合并到此逻辑中,以在请求之间保留状态信息。 这将使我们重写URL两次。 初始页面加载将忽略JavaScript的状态; 它将准备两个信号文件-一个指示对JavaScript的支持,另一个指示对JavaScript的不支持。 第一次URL重写将触发浏览器中的

<?php // demo/javascript_check_nocookie.php
/**
 * This script tries to detect whether a browser will run JavaScript
 */
error_reporting(E_ALL);

function browser_javascript_nocookie()
{
    // SETTINGS SHOULD ALLOW FOR SIMULTANEOUS ACCESS FROM MANY CLIENTS
    $client_agt = !empty($_SERVER['HTTP_USER_AGENT']) ? md5($_SERVER['HTTP_USER_AGENT']) : 'unknown';
    $client_ipa = !empty($_SERVER['REMOTE_ADDR'])     ? $_SERVER['REMOTE_ADDR']          : '1.1.1.1';
    $state_JS   = "js_check.JS.$client_agt.$client_ipa.txt";
    $state_noJS = "js_check.noJS.$client_agt.$client_ipa.txt";

    // IS THERE A SIGNAL STRING IN THE URL?
    $js   = isset($_GET['JS']);
    $nojs = isset($_GET['noJS']);
    if ($js || $nojs)
    {
        // REMOVE THE COMPLEMENTARY STATE FILE
        if ($nojs)
        {
            @unlink($state_JS);
        }
        elseif ($js)
        {
            @unlink($state_noJS);
        }

        // SET UP A REGULAR EXPRESSION TO RESTORE THE ORIGINAL URL
        $rgx
        = '#'         // REGEX DELIMITER
        . '(&|\?)'    // AMPERSAND OR (ESCAPED) QUESTION MARK
        . '(no)?'     // LITERAL STRING no, OPTIONAL
        . 'JS'        // LITERAL STRING JS, REQUIRED
        . '$'         // AT END OF STRING
        . '#'         // REGEX DELIMITER
        ;

        // REMOVE THE SIGNAL STRING FROM THE URL AND REFIRE THE REQUEST
        $request = preg_replace($rgx, NULL, $_SERVER['REQUEST_URI']);
        $refresh = <<<EOR
<meta http-equiv="refresh" content="0;URL='$request'" />
EOR;
        echo $refresh;
        exit;
    }

    // THERE IS NO SIGNAL STRING IN THE URL
    else
    {
        // DOES THE STATE FILE EXIST?
        $js   = file_exists($state_JS);
        $nojs = file_exists($state_noJS);
        if ($nojs || $js)
        {
            if ($nojs)
            {
                @unlink($state_noJS);
                $retval = FALSE;
            }
            elseif ($js)
            {
                @unlink($state_JS);
                $retval = $client_ipa;
            }
            return $retval;
        }

        // THE STATE FILE DOES NOT EXIST
        else
        {
            // WRITE TWO STATE FILES
            file_put_contents($state_JS,   $client_ipa);
            file_put_contents($state_noJS, $client_ipa);

            // PREPARE META-REFRESH TAGS WITH AN EXTRA URL PARAMETER
            $requestjs = $_SERVER['REQUEST_URI'];
            $requestno = $_SERVER['REQUEST_URI'];
            if (strpos($_SERVER['REQUEST_URI'], '?'))
            {
                $requestjs .= "&JS";
                $requestno .= "&noJS";
            }
            else
            {
                $requestjs .= "?JS";
                $requestno .= "?noJS";
            }

            // REFIRE THE REQUEST WITH THE EXTRA URL PARAMETER
            $refresh = <<<EOR
<noscript><meta http-equiv="refresh" content="0;URL='$requestno'" /></noscript>
<script>document.write("<meta http-equiv=\"refresh\" content=\"0;URL='$requestjs'\" />");</script>
EOR;
            echo $refresh;
            exit;
        }
    }
}


// USE CASE
if ($ip_addr = browser_javascript_nocookie())
{
    echo "THIS CLIENT RUNS JAVASCRIPT AT IP ADDRESS: $ip_addr";
}
else
{
    echo "THIS CLIENT DOES NOT SUPPORT JS";
}

Overall, I think the best practices approach to the question of JavaScript is to design your site to work sensibly without JavaScript, and to use JavaScript (jQuery) to provide an enhanced user experience.

总体而言,我认为针对JavaScript问题的最佳做法是将您的网站设计为jQuery )提供增强的用户体验。

Summary

摘要

We have demonstrated convenient ways of getting information about the settings of the client's browser. These techniques will work dependably in almost all cases. They may give you better ways of creating a good browsing experience for your client community. The code snippets here have been tested in Firefox, Chrome and IE. You can copy them and install them on your server to see them in action.

我们已经展示了获取有关客户端浏览器设置信息的便捷方法。 这些技术几乎可以在所有情况下可靠地工作。 它们可以为您提供更好的方法,为您的客户社区创造良好的浏览体验。 此处的代码段已在Firefox,Chrome和IE中进行了测试。 您可以复制它们并将它们安装在服务器上以查看它们的运行情况。

Addendum

附录

Further reading on the state of the art in client browser data storage (beyond cookies):

进一步阅读客户端浏览器数据存储中的最新技术(除了cookie):

http://www.sitepoint.com/html5-browser-storage-past-present-future/ http://www.sitepoint.com/html5-browser-storage-past-present-future/

Enable/Disable Cookies in Internet Explorer 11

在Internet Explorer 11中启用/禁用Cookie

1. Click the gear in the upper right corner of the browser window

1.单击浏览器窗口右上角的齿轮

2. Click "Internet Options"

2.点击“ Internet选项”

3. Click "Privacy" tab

3.点击“隐私”标签

4. Drag the slider to the top to disable cookies

4.将滑块拖动到顶部以禁用cookie

5. Click "Default" to enable cookies

5.单击“默认”以启用cookie

Enable/Disable JavaScript in Internet Explorer 11

在Internet Explorer 11中启用/禁用JavaScript

1. Click the gear in the upper right corner of the browser window

1.单击浏览器窗口右上角的齿轮

2. Click "internet Options"

2.点击“互联网选项”

3. Click "Security" tab

3.单击“安全性”选项卡

4. Click "Custom Level"

4.单击“自定义级别”

5. Scroll down to "Scripting"

5.向下滚动到“脚本”

6. Select the appropriate setting under "Active scripting"

6.在“活动脚本”下选择适当的设置

Find Cookies in Chrome 38

在Chrome 38中查找Cookie

Type this into your browser address bar: chrome://settings/cookies

在浏览器地址栏中输入以下内容:

Enable/Disable Cookies and JavaScript in Chrome 38

在Chrome 38中启用/禁用Cookie和JavaScript

https://support.google.com/accounts/answer/61416?hl=en https://support.google.com/accounts/answer/61416?hl=zh_CN https://support.google.com/adsense/answer/12654?hl=en https://support.google.com/adsense/answer/12654?hl=zh_CN

References and Further Reading:

参考资料和进一步阅读:

http://roy.gbiv.com/ http://roy.gbiv.com/ https://www.ietf.org/rfc/rfc2616.txt https://www.ietf.org/rfc/rfc2616.txt http://www.w3.org/TR/WCAG20-TECHS/H76.html http://www.w3.org/TR/WCAG20-TECHS/H76.html https://developer.mozilla.org/en-US/docs/Web/API/document.cookie https://developer.mozilla.org/zh-CN/docs/Web/API/document.cookie http://en.wikipedia.org/wiki/Meta_refresh http://en.wikipedia.org/wiki/Meta_refresh http://www.w3schools.com/tags/ref_httpmethods.asp http://www.w3schools.com/tags/ref_httpmethods.asp http://www.w3schools.com/tags/tag_noscript.asp http://www.w3schools.com/tags/tag_noscript.asp

Please give us your feedback!

请给我们您的反馈意见!

If you found this article helpful, please click the "thumb's up" button below. Doing so lets the E-E community know what is valuable for E-E members and helps provide direction for future articles.  If you have questions or comments, please add them.  Thanks!

如果您发现本文有帮助,请单击下面的“竖起大拇指”按钮。 这样做可以使EE社区了解对EE成员有价值的内容,并为将来的文章提供指导。 如果您有任何问题或意见,请添加。 谢谢!

翻译自: https://www.experts-exchange.com/articles/17334/Detecting-Client-Browser-Settings-for-Cookies-and-JavaScript.html

在客户端设置cookie

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值