2011-12-16 67 views
1

上的文字當我運行這個簡單的腳本greasemonkey文件撰寫不會顯示網頁

alert("hello"); 
alert(document.location); 
document.write("hello"); 
alert("hello"); 

只有前兩個語句的工作,第三和第四條語句什麼也不做。

這裏有什麼問題?

+0

他們似乎對我工作正常是你得到任何JavaScript錯誤? – 2011-12-16 20:19:08

回答

1

看起來document.write()只能從Greasemonkey間歇性地工作 - 可能是由於沙箱。

我還沒有找到一個重複這個問題的萬無一失的食譜呢。

但是,基於DOM的方法似乎總是奏效。使用此代碼:

//--- Erase everything from the page's body: 
var b   = document.body; 
var p   = b.parentNode; 
p.removeChild (b); 


//--- Add our new text or HTML. 
var newB  = document.createElement ("BODY"); 
newB.innerHTML = "Hello"; 
p.appendChild (newB); 




PS:我更新了對方的回答也是如此。

+0

這有效,但我想用`greasemonkey`解決這個問題。在螢火蟲控制檯工作的問題沒有問題的代碼。 – xralf 2011-12-16 21:04:19