Skip to content

Instantly share code, notes, and snippets.

@yannickcr
Created May 1, 2014 17:12
Show Gist options
  • Save yannickcr/5472d08a75e43174e249 to your computer and use it in GitHub Desktop.
Save yannickcr/5472d08a75e43174e249 to your computer and use it in GitHub Desktop.
Testing SockJS iframe-htmlfile transport under IE8
  • SockJS-node is running on 192.168.0.21:8081
  • Sending a message from the main page works everywere
  • Sending a message from the iframe or popup does not works in IE8
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=8" />
<meta charset="UTF-8" />
<script src="lib/sockjs.js"></script>
</head>
<body>
<button id="sendmessage">Send from main page</button>
<button id="popup">Open popup</button>
<iframe src="/iframe.html"></iframe>
<script>
// SockJS-node running on 192.168.0.21:8081
var sock = new SockJS('http://192.168.0.21:8081/echo', null, {
protocols_whitelist: [
'iframe-htmlfile' // The transoport we want to test
]
});
// Informative messages
sock.onopen = function() {
console.log('open');
};
sock.onmessage = function(e) {
console.log('message', e.data);
};
sock.onclose = function() {
console.log('close');
};
// Open the iframe in a popup
document.querySelector('#popup').attachEvent('onclick', function() {
window.open('/iframe.html', 'WindowName', 'menubar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes');
}, true);
// Send a message from the main page
document.querySelector('#sendmessage').attachEvent('onclick', function() {
sock.send("Here's some text that the server is urgently awaiting!");
}, true);
</script>
</body>
</html>
<!doctype html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=8" />
<meta charset="UTF-8" />
<title></title>
</head>
<body>
<button id="sendmessage">Send from popup/iframe</button>
<script>
document.querySelector('#sendmessage').attachEvent('onclick', function() {
// Use opener (popup) or parent (iframe) SockJS instance to send a message
(window.opener || window.parent).sock.send("Here's some text that the server is urgently awaiting!");
}, true);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment