Since I don't how to do this in plain JavaScript, I usually embed jQuery and use the following function:
Code:
$(document).ready(function() {
// your code
};
(You can download an example epub3 book with an embedded jQuery file
here.)
If adding
ready() doesn't do the trick, post an example epub3 file.