Userscript to wait for page to load before executing code techniques?

前端 未结 7 1993
迷失自我
迷失自我 2020-11-27 10:24

I\'m writing a Greasemonkey user script, and want the specific code to execute when the page completely finishes loading since it returns a div count that I want to be displ

7条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-27 11:03

    wrapping my scripts in $(window).load(function(){ }) never failed for me.

    maybe your page has finished, but there is still some ajax content being loaded.

    if that is the case, this nice piece of code from Brock Adams can help you:
    https://gist.github.com/raw/2625891/waitForKeyElements.js

    i usually use it to monitor for elements that appears on postback.

    use it like this: waitForKeyElements("elementtowaitfor", functiontocall)

提交回复
热议问题