0

this greasemonkey script..

document.getElementById("leftsidebar").style.backgroundColor="rgb(211,211,100)"

..takes no effect, because the webpage is not yet loaded completely when greasemonkey is executing this script. -What do I have to do to execute the script not until the webpage is loaded completely?

Heiko
  • 17
  • 7
  • Some solutions of [Why does jQuery or a DOM method such as getElementById not find the element?](http://stackoverflow.com/q/14028959/1529630) would be applicable. – Oriol Aug 16 '16 at 00:40

1 Answers1

0

If you are on Greasemonkey version 3.6 or higher, you can the @run-at meta key inside the metadata block:

// @run-at  document-idle

See the documentation

Alternatively, you can use the window.onload callback:

window.onload = function() {
    // all the rest of your code that must run later comes here.
}
trincot
  • 211,288
  • 25
  • 175
  • 211