<?php if(your condition){ echo "<script> window.onload = function() { yourJavascriptFunction(param1, param2); }; </script>"; ?>