Skip to content

Instantly share code, notes, and snippets.

@arantius
Created February 6, 2012 17:28
Show Gist options
  • Save arantius/1753499 to your computer and use it in GitHub Desktop.
Save arantius/1753499 to your computer and use it in GitHub Desktop.
greasemonkey issue 1508 test case
// ==UserScript==
// @name iframe test
// @version 1
// @namespace iframe
// @include http://localhost/1
// @include http://localhost/2
// ==/UserScript==
function tdump(msg) {
dump(new Date().toLocaleTimeString() + ' ' + msg + '\n');
}
if(location.path === '/1') {
window.addEventListener('message', function(e) {
tdump(e.data);
}, false);
}
if (location.pathname === '/2') {
tdump('the userscript has now been executed in the iframe');
} else {
document.documentElement.innerHTML =
'<iframe src=http://localhost/2></iframe>';
document.querySelector('iframe').onload = function(e) {
tdump('iframe onload event (' + e.target.src + ')');
};
setTimeout(function() {
document.querySelector('iframe').src = 'about:blank';
}, 5000);
setTimeout(function() {
document.querySelector('iframe').src = 'http://localhost/2';
}, 10000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment