0

Specifically, I want to call this function when the Facebook page is loaded with:

window.addEventListener('load', myFunc);

However, it seems like the function gets called only once (after DOM is constructed). I also want that function to get called dynamically when I scroll down the bottom of the page and more data are fetched. What kind of event listener should I set? What are the alternative solutions?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
knd
  • 1,662
  • 2
  • 15
  • 27
  • Since you tagged it as Chrome, take a look at WebKitMutationObserver. Here's an example: http://stackoverflow.com/questions/2844565/is-there-a-jquery-dom-change-listener/11546242#11546242 – Vlad Magdalin Jan 26 '13 at 22:01

1 Answers1

2

There is no good cross browser way to detect generic changes to the DOM. Here are some of your options:

  1. DOM mutation observers (only supported in some browsers): newer mutation observers and deprecated mutation events.

  2. A timer to regularly poll the content to see if new stuff has been added.

  3. Monitor scroll events and trigger some polling when the scrollbar gets to the bottom (a potentially more efficient version of #2).

jfriend00
  • 683,504
  • 96
  • 985
  • 979