Categories
JavaScript Answers

How to hide a mobile browser’s address bar with JavaScript?

Spread the love

Sometimes, we want to hide a mobile browser’s address bar with JavaScript.

In this article, we’ll look at how to hide a mobile browser’s address bar with JavaScript.

How to hide a mobile browser’s address bar with JavaScript?

To hide a mobile browser’s address bar with JavaScript, we scroll down the page slightly.

For instance, we write

window.addEventListener("load", () => {
  setTimeout(() => {
    window.scrollTo(0, 1);
  }, 0);
});

to scroll down the page when it’s loaded.

We listen to the load event with addEventListener.

Then we call window.scrollTo to scroll down the page by 1 pixel in the setTimeout callback when the load event is triggered when the page is loaded to hide the address bar.

Conclusion

To hide a mobile browser’s address bar with JavaScript, we scroll down the page slightly.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *