[英]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.