Greasemonkey simple html text replacing not workin

2019-06-10 18:54发布

问题:

I need to replace all the olds links of an HTML page by the new web page so I created the following script

document.body.innerHTML.replace('www.forumoldpage','www.forumnewpage');

Save it but when I open the web page do nothing.

There's something wrong with the code or do I forgot something to do?

回答1:

I was led to this question when trying to create my very first greasemonkey script, so I thought it's for the benefit of everybody if this question has an answer. Try this:

document.body.innerHTML = document.body.innerHTML.replace('www.forumoldpage','www.forumnewpage');

replace gives you a new string with the replacement effected, but you still have to replace the contents of the web page.