GD77 Posted July 7, 2012 Share Posted July 7, 2012 Hello: How to pass a js command like parent.function(); with php without onClick just php... need this to be apllied before header(); or with it Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/265352-help-with-passing-js-command-with-php-to-a-parent-page/ Share on other sites More sharing options...
smoseley Posted July 7, 2012 Share Posted July 7, 2012 Javascript is run in the browser, in the HTTP response. It's impossible to execute a JS command before the HTTP header is sent. If you explain what you're trying to do, there's probably an alternative solution. Quote Link to comment https://forums.phpfreaks.com/topic/265352-help-with-passing-js-command-with-php-to-a-parent-page/#findComment-1359871 Share on other sites More sharing options...
smoseley Posted July 7, 2012 Share Posted July 7, 2012 PS - if you just want to run a JS command as soon as the page loads, do this: <html> <head> <script type="text/javascript"> parent.function(); </script> That will execute before the HTML renders. Quote Link to comment https://forums.phpfreaks.com/topic/265352-help-with-passing-js-command-with-php-to-a-parent-page/#findComment-1359872 Share on other sites More sharing options...
smoseley Posted July 7, 2012 Share Posted July 7, 2012 PPS - Sounds like you're using frames. If you want more control over how your content loads, consider switching to AJAX. Quote Link to comment https://forums.phpfreaks.com/topic/265352-help-with-passing-js-command-with-php-to-a-parent-page/#findComment-1359873 Share on other sites More sharing options...
GD77 Posted July 7, 2012 Author Share Posted July 7, 2012 PS - if you just want to run a JS command as soon as the page loads, do this: <html> <head> <script type="text/javascript"> parent.function(); </script> That will execute before the HTML renders. Actually that is what I ve done: $msg="Welcome, You Are Logged In."; sleep(2); echo "<script type='text/javascript'>parent.boxOFF();</script>"; and it s working but now the echo command is preventing the $msg data from showing Quote Link to comment https://forums.phpfreaks.com/topic/265352-help-with-passing-js-command-with-php-to-a-parent-page/#findComment-1359876 Share on other sites More sharing options...
GD77 Posted July 7, 2012 Author Share Posted July 7, 2012 echo solved the delay and the $msg problem with this: $msg="Welcome, You Are Logged In. <script type='text/javascript'> function delayed(){parent.boxOFF();parent.location.reload(true);} window.setTimeout(delayed,2000);</script>"; Don t know if their is a another or better way... Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/265352-help-with-passing-js-command-with-php-to-a-parent-page/#findComment-1359883 Share on other sites More sharing options...
smoseley Posted July 7, 2012 Share Posted July 7, 2012 For what it looks like you're trying to do, that should work fine. Quote Link to comment https://forums.phpfreaks.com/topic/265352-help-with-passing-js-command-with-php-to-a-parent-page/#findComment-1359925 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.