如何在移动 Chrome 浏览器中检查 Data Saver 是否打开?
How to check whether Data Saver is on or not in Mobile Chrome Browser?
在移动 Chrome 浏览器中启用流量节省选项时,网站的行为会有所不同。使用 JavaScript.
确定是否启用 Data Saver 的最佳方法是什么
来自常见问题
Can I detect if the user has Data Compression Proxy turned on?
Yes, kind of. As of Chrome 49 (Beta in Feb 2nd 2016, Estimated stable date
in late March) when the user has enabled the Data Saver feature in Chrome,
Chrome will add a save-data HTTP Header with the value 'on' to each HTTP
Request. The HTTP Header will not be present when the feature is turned off.
Use this as a signal of intent from the user that they are conscious of the
amount of data that they are using and not that their connection is going
through the Data Compression Proxy. For instance, the HTTP Header will be
set when the user visits a site over HTTPS even though secure connections
are not passed through the Data Compression Proxy.
按照常见问题解答中的建议,我尝试扫描 Headers 列表并检查 Save-Data
参数是否存在。
我正在移动 Chrome、
中关注 Headers
通过扫描此数据,如果 Save-Data
header 存在,我们可以假设 Data Saver
是 on
/*
* This is PHP Code
* will not work on clicking "Run Code Snippet"
* Host this code on php server as .php file
*/
<?php
header('Content-Type: application/json');
$headers = getallheaders();
$datasaver = false;
foreach($headers as $key=>$val){
if(strtolower($key) == 'save-data' && $val == 'on'){
$datasaver = true;
}
}
$status = array('data-saver'=>$datasaver);
echo json_encode($status);
?>
现在是 2018 年,official documentation is saying 您可以像这样检测 JS 中的数据保存选项:
if ("connection" in navigator) {
if (navigator.connection.saveData === true) {
// Implement data saving operations here.
}
}
在移动 Chrome 浏览器中启用流量节省选项时,网站的行为会有所不同。使用 JavaScript.
确定是否启用 Data Saver 的最佳方法是什么来自常见问题
Can I detect if the user has Data Compression Proxy turned on?
Yes, kind of. As of Chrome 49 (Beta in Feb 2nd 2016, Estimated stable date in late March) when the user has enabled the Data Saver feature in Chrome, Chrome will add a save-data HTTP Header with the value 'on' to each HTTP Request. The HTTP Header will not be present when the feature is turned off. Use this as a signal of intent from the user that they are conscious of the amount of data that they are using and not that their connection is going through the Data Compression Proxy. For instance, the HTTP Header will be set when the user visits a site over HTTPS even though secure connections are not passed through the Data Compression Proxy.
按照常见问题解答中的建议,我尝试扫描 Headers 列表并检查 Save-Data
参数是否存在。
我正在移动 Chrome、
中关注 Headers通过扫描此数据,如果 Save-Data
header 存在,我们可以假设 Data Saver
是 on
/*
* This is PHP Code
* will not work on clicking "Run Code Snippet"
* Host this code on php server as .php file
*/
<?php
header('Content-Type: application/json');
$headers = getallheaders();
$datasaver = false;
foreach($headers as $key=>$val){
if(strtolower($key) == 'save-data' && $val == 'on'){
$datasaver = true;
}
}
$status = array('data-saver'=>$datasaver);
echo json_encode($status);
?>
现在是 2018 年,official documentation is saying 您可以像这样检测 JS 中的数据保存选项:
if ("connection" in navigator) {
if (navigator.connection.saveData === true) {
// Implement data saving operations here.
}
}