Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
test for Greasemonkey #1904
// ==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);
<!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
You can’t perform that action at this time.