Last active
August 29, 2015 13:58
-
-
Save arantius/10079391 to your computer and use it in GitHub Desktop.
test for Greasemonkey #1904
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
// ==UserScript== | |
// @name callback stubber | |
// @namespace x | |
// @include http://localhost/cb.html | |
// @version 1 | |
// @grant none | |
// ==/UserScript== | |
unsafeWindow.cb = function(a) { console.log('script cb', a); } | |
var obj = { | |
cb: function(a) { console.log('script obj.cb', a); } | |
}; | |
unsafeWindow.obj = obj; | |
document.getElementById('event2').addEventListener( | |
'click', obj.cb, false); |
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> | |
<head> | |
<meta charset="utf-8"> | |
<title>Content Callback Test</title> | |
</head> | |
<body> | |
<button onclick="cb('direct')">Direct Call</button><br> | |
<button onclick="obj.cb('direct')">Direct Call (obj)</button></br> | |
<button id="event1">Event Listener</button><br> | |
<button id="event2">Event Listener (obj)</button><br> | |
</body> | |
<script> | |
function cb(a) { | |
console.log('in-page cb', a); | |
} | |
var obj = { | |
cb: function(a) { | |
console.log('in-page obj.cb', a); | |
} | |
} | |
document.getElementById('event1').addEventListener( | |
'click', cb, false); | |
document.getElementById('event2').addEventListener( | |
'click', obj.cb, false); | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment