taskpane.html 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8" />
  5. </head>
  6. <script type="text/javascript" src="../js/util.js"></script>
  7. <script type="text/javascript">
  8. function load() {
  9. if (typeof Worker === 'undefined') {
  10. console.log('当前浏览器不支持webworker')
  11. } else {
  12. let worker = new SharedWorker(GetResourcePath() + '/../js/worker.js')
  13. worker.port.addEventListener(
  14. 'message',
  15. (e) => {
  16. console.log(e.data)
  17. },
  18. false
  19. )
  20. worker.port.start()
  21. window.worker = worker
  22. }
  23. }
  24. function sendMsg() {
  25. if (window.worker) {
  26. var txt = document.querySelector('message').nodeValue
  27. window.worker.port.postMessage(txt)
  28. }
  29. }
  30. </script>
  31. <body onload="load">
  32. <div class="global">
  33. <section>
  34. <caption> Message </caption>
  35. <dt id="messagebox"></dt>
  36. </section>
  37. <section>
  38. <input type="text" id="message" />
  39. <button onclick="sendMsg">Send</button>
  40. </section>
  41. </div>
  42. </body>
  43. <style>
  44. .global {
  45. font-size: 15px;
  46. min-height: 95%;
  47. }
  48. .divItem {
  49. margin-left: 5px;
  50. margin-bottom: 18px;
  51. font-size: 15px;
  52. word-wrap: break-word;
  53. }
  54. </style>
  55. </html>