我可以从我的页面调用我的自定义Greasemonkey的function()吗?
例如,
我创建了一个包含do_this()函数的GM脚本.我希望my-web-site.com调用do_this()函数.但我不能.
我知道,我可以通过做unsafeWindow.do_this()但这样做阻止我调用GM_xmlhttpRequest().
有任何想法吗?
在这里工作的例子,首先创建元素然后addEventListener
// ==UserScript==
// @name GM addEventListener Function Test
// @namespace ewwink.com
// @description GM addEventListener Function Test
// @include http://*
// ==/UserScript==
document.body.innerHTML+='<input type="image" id="alertMeID" onclick="do_this()" style="position:fixed;top:0;left:0" src="http://i55.tinypic.com/2nly5wz.gif" />';
document.getElementById('alertMeID').addEventListener('click', do_this, false);
function do_this(){
alert('hello World!, today is: '+new Date())
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5889 次 |
| 最近记录: |