문제

I'm working on a JavaScript library which needs to give the user the ability to run some code on load. Of course, I'm familiar with window.onload, and things like $(function() {}); with jQuery. But I don't want to be dependent on another library, and I want this particular function (along with the rest of the lib, of course) to be cross-browser.

So is there an accepted way of attaching to the onload function without overriding another library's load functionality (or having mine overwritten if they include another lib after mine)?

도움이 되었습니까?

해결책

Expose an initialization/onload method and require it be called by the consumer on load. In other words, push the issue off to whomever is using the library and will likely have a convenient method like that offered by jQuery.

This is a solved problem but it isn't simple: the answer to "$(document).ready equivalent without jQuery" has the code of how jQuery does this.

More hits: javascript onload without jQuery

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top