How to execute JavaScript after page load?

前端 未结 6 848
我寻月下人不归
我寻月下人不归 2020-12-10 11:23

I would like to execute a JavaScript function after the page was loaded. At the moment I have a commandButton and everything works fine. However it would be more comfortable

6条回答
  •  感情败类
    2020-12-10 11:40

    There are 2 ways that work for me, when I want to execute a JS function after page load in Primefaces:

    • either use jQuery (as it is already used by Primefaces), best solution is to nest document.ready twice, so that my JS code is executed after all Primefaces code:
      • jQuery(document).ready(function () { jQuery(document).ready(function () { // twice in document.ready to execute after Primefaces callbacks PathFinder.findAndGo(); }); });
    • or use p:remoteCommand with autorun, and place oncomplete JS callback on it
      • this way form is submitted by AJAX to server but no listener executed on server side, a JS callback is executed afterwards

提交回复
热议问题