【发布时间】:2013-03-18 05:43:31
【问题描述】:
如何从链接中调用 Tampermonkey 函数?
这是我尝试过的。使用 Tampermonkey,我可以插入如下链接:
var aNode = document.createElement('a');
var aText = document.createTextNode('will it run');
aNode.appendChild(aText);
aNode.href = 'javascript:runTest();';
document.body.insertBefore(aNode, document.body.firstChild);
function runTest() {
alert('it ran!');
};
当调用链接时,应该调用函数 runTest()。它不是。而是出现以下错误消息:
Uncaught ReferenceError: runTest is not defined
【问题讨论】:
标签: javascript function hyperlink call tampermonkey