Apple Books supports JavaScript similarly to Safari. In books, JavaScript allows for features like drag and drop, and touch or mouse events to initiate audio or animation. However, scripts developed for books should take into account the following best practices:
Develop scripts that perform well on both macOS and iOS devices. Interactivity on desktop computers requires input from a mouse while interactivity on iOS devices require touch input.
When developing interactive books, be mindful of file size and the amount of interactivity on each page. Interactivity can be a great addition to a book, but good performance must be a priority.
Books must not rely on external resources. Do not use JavaScript to access resources outside of the book. Books must be self-contained.
Books must not include databases. Apple Books does not sync the status of AJAX, HTML5 databases, or SQL, and therefore does not save this information. Do not include these resources for interactivity in your books.
Use JavaScript for triggering interactivity, but use CSS for animations and transitions. Animations and transitions perform best when created using CSS rather than JavaScript. Use CSS 3D transforms instead of setting top/bottom/left/right positions— this creates smoother transitions because they are hardware accelerated, but should be reserved for high-priority elements.
Avoid using the JavaScript alert feature. Apple recommends that you not use the JavaScript alert feature, which is frequently used to alert users of errors. If you choose to use this feature, remember that your readers will see them.