javascript - Insert JS in PHP - on load scroll


I'm trying to get my page to scroll to a certain number of pixels down the page when it loads. I'm editing a wordpress template that I created so it's in PHP.

I've got:

echo "<body onload='window.scroll(0,400)'>";

at the top of the php file but it's not working. what do I need to do to make this work?




Use this code in yourheader.php on your child theme or any similar.

<script type="text/javascript">
    $( document ).ready(function() {

Don't forget insert jquery in your head if this code not working

    <script src=""></script>



The onload event attribute is expecting a function, and you can do that inline withjavascript: in the attribute...

echo "<body onload='javascript:window.scroll(0,400);'>";

People are also looking for solutions to the problem: Android - Php receive string from android


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.