Created
November 7, 2010 12:48
-
-
Save fillano/666105 to your computer and use it in GitHub Desktop.
測試瀏覽器的global worker scope中所支援的物件,這是網頁端,需要與worker端的程式來協作
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="zh-TW"> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf8"> | |
<style> | |
div { | |
border: solid 2px #336699; | |
margin: 10px; | |
padding: 5px; | |
border-radius: 5px; | |
-moz-border-radius: 5px; | |
vertical-align: top; | |
text-align: center; | |
display: inline-block; | |
} | |
#panel { | |
width: 400px; | |
background: #AACCEE; | |
text-align: left; | |
font-size: 10pt; | |
display: block; | |
} | |
#panel1 { | |
width: 400px; | |
background: #AACCEE; | |
text-align: left; | |
font-size: 10pt; | |
display: block; | |
} | |
</style> | |
</head> | |
<body> | |
<div>Web Worker Global Scope<div id="panel"></div></div> | |
<div>Shared Worker Global Scope<div id="panel1"></div></div> | |
</body> | |
</html> | |
<script> | |
try { | |
var worker = new Worker('test644.js'); | |
worker.onmessage = function(e) { | |
document.getElementById('panel').innerHTML += e.data; | |
}; | |
worker.postMessage('start'); | |
} catch(e) { | |
document.getElementById('panel').innerHTML += '<span style="color:red">No Worker support.</span>'; | |
} | |
try { | |
var sharedworker = new SharedWorker('test644a.js','shared'); | |
sharedworker.port.onmessage = function(e) { | |
document.getElementById('panel1').innerHTML += e.data; | |
} | |
sharedworker.port.postMessage('start'); | |
} catch(e) { | |
document.getElementById('panel1').innerHTML += '<span style="color:red">No SharedWorker support.</span>'; | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment