12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8" />
- </head>
- <script type="text/javascript" src="../js/util.js"></script>
- <script type="text/javascript">
- function load() {
- if (typeof Worker === 'undefined') {
- console.log('当前浏览器不支持webworker')
- } else {
- let worker = new SharedWorker(GetResourcePath() + '/../js/worker.js')
- worker.port.addEventListener(
- 'message',
- (e) => {
- console.log(e.data)
- },
- false
- )
- worker.port.start()
- window.worker = worker
- }
- }
- function sendMsg() {
- if (window.worker) {
- var txt = document.querySelector('message').nodeValue
- window.worker.port.postMessage(txt)
- }
- }
- </script>
- <body onload="load">
- <div class="global">
- <section>
- <caption> Message </caption>
- <dt id="messagebox"></dt>
- </section>
- <section>
- <input type="text" id="message" />
- <button onclick="sendMsg">Send</button>
- </section>
- </div>
- </body>
- <style>
- .global {
- font-size: 15px;
- min-height: 95%;
- }
- .divItem {
- margin-left: 5px;
- margin-bottom: 18px;
- font-size: 15px;
- word-wrap: break-word;
- }
- </style>
- </html>
|