ここに私のスクリプトコードがあります:
// ==UserScript==
// @name test
// @description test
// @include http://*
// @copyright Bruno Tyndall
// ==/UserScript==
var main = function() {
var b = document.getElementsByTagName('body')[0];
var t = document.createElement('div');
t.innerHTML = '<a href="javascript:void(0);" style="color:white;">Hello World</a>';
t.style.position = 'absolute';
t.style.zIndex = 1000;
t.style.bottom = '5px';
t.style.right = '5px';
t.firstChild.setAttribute('onclick', 'test();');
b.appendChild(t);
}
var test = function() {
alert("Hello World");
}
main();
私が抱えている唯一の問題は、Hello World をクリックすると、ページで test() 関数が見つからないことです。このようにページに関数をinnerHTML'ingすることで解決する必要はないことを教えてください。別の方法はありますか?
ありがとう。