Web Worker
2021-04-09 21:25
标签:加载 ons explorer fun span viewport fine xpl com Web Worker 标签:加载 ons explorer fun span viewport fine xpl com 原文地址:https://www.cnblogs.com/wxy0715/p/12442115.htmlDOCTYPE html>
html lang="en">
head>
meta charset="UTF-8">
meta name="viewport" content="width=device-width, initial-scale=1.0">
meta http-equiv="X-UA-Compatible" content="ie=edge">
title>Documenttitle>
head>
body>
p>计数: output id="result">output>p>
button onclick="startWorker()">开始工作button>
button onclick="stopWorker()">停止工作button>
p>strong>注意:strong> Internet Explorer 9 及更早 IE 版本浏览器不支持 Web Workers.p>
script>
var w;
function startWorker() {
if(typeof(Worker) !== "undefined") {
if(typeof(w) == "undefined") {
w = new Worker("demo_workers.js");
}
w.onmessage = function(event) {
document.getElementById("result").innerHTML = event.data;
};
} else {
document.getElementById("result").innerHTML = "抱歉,你的浏览器不支持 Web Workers...";
}
}
function stopWorker()
{
w.terminate();//停止工作
w = undefined;
}
script>
body>
html>