本文主要是介绍webworker测试示例,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>Web Worker</title>
</head>
<body><script type="app/worker" id="worker">//注意必须指定<script>标签的type属性是一个浏览器不认识的值onmessage = function(event) {console.log("收到主线程的数据:", event.data);postMessage("end")}</script><script>var blob = new Blob([document.querySelector("#worker").textContent]);var url = window.URL.createObjectURL(blob);var worker = new Worker(url);worker.onmessage = function(event) {console.log("收到worker的数据:", event.data);worker.terminate();};worker.postMessage("start");</script>
</body>
</html>
这篇关于webworker测试示例的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!