簡體   English   中英

document.write將不會在網頁上顯示文本

[英]document.write won't show the text on the web page

當我運行這個簡單的greasemonkey腳本時

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

僅前兩個語句起作用,第三和第四條語句不起作用。

這有什么問題嗎?

似乎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:我也更新了其他答案。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM