We help IT Professionals succeed at work.

How to Detect Page Bottom Programatically with JavaScript on Initial webpage load?

894359
894359 asked
on
336 Views
Last Modified: 2017-05-22
I want to know if there is a way to detect with JavaScript when I have reached the bottom of a webpage (***WHEN IT IS INITIALLY LOADNG***), right before the closing "body" tag?

I can't add any code manually/directly to ALL the HTML pages, so this needs to be handled via a JS included script therefore this is why I need to detect programatically

I want to fire a method right before the closing body tag.

The problem I'm trying to solve is that I have a bootstrap loader file that loads a js script in the head of every webpage. Every webpage is additionally supposed to have a method called immediately called, right before the closing body tag, on the initial load.
Try{ _satellite.pageBottom()}catch(e){}

Open in new window

But the issue is, the bootstrap loader file will be deployed to 3rd party websites also and those sites can't put the method on their pages before the closing body tag, so trying to find a happy medium and solution. Currently I'm just doing a time delay in the bootstrap loader file to invoke the "_satellite.pageBottom() method but this is far from being close to accurate and causes timing issues.
Comment
Watch Question

CERTIFIED EXPERT
Distinguished Expert 2017

Commented:
Try with the following code.It uses window.onscroll method and you can adjust the point at when you want to alert you or firing a function

window.onscroll = function(e) {
    if ((window.innerHeight + window.scrollY) >= document.body.offsetHeight) {
        alert('bottom!!!');
//Or another function that you want to fire.
    }
};

Open in new window

Author

Commented:
Hi Leonidas,
Your solution won't work. It requires scrolling and will fire every time a users scrolls to the bottom of the page.. I need something that happens while the page is loading and only once.

Thanks!
CERTIFIED EXPERT
Distinguished Expert 2017

Commented:
Υou set the px before at the point that you want to execute the code and then in your function you use the e.preventDefault or the one method

Author

Commented:
Sorry not following you? Can you provide a working example?
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
Correct, I just don't think it is possible!
Thanks for the great responds!

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.