我有一个在 FireFox 中使用 unsafeWindow 的脚本,因为它不起作用,我已经搜索了另一个选项,并找到了它,我只是想知道:如何将我的用户脚本中的变量用于 unsafeWindow 解决方法?
我的代码是:
// ==UserScript==
// @name Test
// @description Test
// @include http://www.google*
// ==/UserScript==
var toAlert = "This is what I want to alert...";
alert("Before implementation...");
contentEval( function(){ alert(toAlert);});
alert("And after...");
function contentEval(source) {
// Check for function input.
if ('function' == typeof source) {
// Execute this function with no arguments, by adding parentheses.
// One set around the function, required for valid syntax, and a
// second empty set calls the surrounded function.
source = '(' + source + ')();'
}
// Create a script node holding this source code.
var script = document.createElement('script');
script.setAttribute("type", "application/javascript");
script.textContent = source;
// Insert the script node into the page, so it will run, and immediately
// remove it to clean up.
document.body.appendChild(script);
document.body.removeChild(script);
}
它不起作用......我做错了什么?