假设我在脚本的最顶部有一些移动检查:
if (isMobile) {
window.location.href = '/m/' + window.location.pathname + window.location.search;
}
Run Code Online (Sandbox Code Playgroud)
而且我还在代码中(甚至在异步加载的其他模块中)有一些指标,这些指标被发送到我的指标服务器。
我的问题是:如何停止执行低于我的window.location更改的所有内容?或者更好的是,如何停止整个 javascript 引擎,使其不执行任何其他异步加载的模块?
我知道我可以通过许多不同的方式进行移动代理,但在此任务中,我的移动重定向必须在客户端运行,这是给定的。
我已经用PHP编写了websocket服务器/客户端代码,并且在两年内为我工作。现在它不起作用,说:Error during WebSocket handshake: Incorrect 'Sec-WebSocket-Accept' header value
我的客户端代码本质上是这样的:
socket = new WebSocket("ws://<?= EVENT_SERVER_ADDR ?>:"+EVENT_SERVER_PORT+"<?= EVENT_SERVER_WWW_PATH ?>");
Run Code Online (Sandbox Code Playgroud)
PHP服务器端代码是这样的:
list ($resource, $host, $connection, $version, $origin, $key, $protocol, $upgrade) = $this->getheaders ($buffer);
$this->log ("Handshaking...");
$reply =
"HTTP/1.1 101 Switching Protocols\r\n" .
"Upgrade: {$upgrade}\r\n" .
"Connection: {$connection}\r\n" .
"Sec-WebSocket-Version: {$version}\r\n" .
"Sec-WebSocket-Origin: {$origin}\r\n" .
"Sec-WebSocket-Location: ws://{$host}{$resource}\r\n" .
"Sec-WebSocket-Accept: " . $this->calcKey ($key) . "\r\n";
if ($protocol)
$reply .= "Sec-WebSocket-Protocol: $protocol\r\n";
$reply .= "\r\n";
// Closes the handshake
socket_write ($user->socket, $reply, strlen ($reply)); …Run Code Online (Sandbox Code Playgroud)