Fixing that address bar issue in mobile browsers once and for all šŸ¤¬

Ishwar Rimal
2 min readFeb 1, 2021

--

image from freepik

Does your app require a fixed address bar in mobile browsers? Read mode intended to solve problem, creates a lot of problem for some use case. The sudden disappearing and appearing of the address bar as you scroll through mobile browser is pain in the ASS at times.

My use case was that I wanted a fixed address bar when my app was in certain state. It didnā€™t matter if the address bar was hidden or visible. But having a changing behaviour caused terrible problems with styling.

Here are some of the solutions I tried in progressive steps. If any of these works for your use case, you need not go to next step.

  1. HTML5 fullScreen api.

This works but is not enough. Works great for android based phone but for iOS it doesnā€™t solve problem.

2. Always hide the address bar with window.scrollTo(0,1)

Youā€™ve to scroll the entire body by code. And for some reason this didnā€™t work for me.

3. Always show the address bar with window.scrollTo(0,0)

This shit didnā€™t work too.

4. Use some css hack with html and body tag

Setting position as fixed for body is the trick.

html {overflow: hidden;width: 100%;}body {height: 100%;position: fixed;overflow-y: scroll;-webkit-overflow-scrolling: touch;}

Though my use case was quite complex, the overflow property in html and position property in body was added and removed dynamically.

Feel free to comment if you need any help.

I hope you found this article useful. I would love to hear your thoughts. šŸ˜‡

Thanks for reading. šŸ˜Š

Cheers! šŸ˜ƒ

If you find this article useful, you can show your appreciation by clicking on the clap button. As the saying goes, ā€˜When we give cheerfully and accept gratefully, everyone is blessedā€™.

--

--

Ishwar Rimal

Senior FrontEnd Engineer at Intuit. 8 years experience. I write articles on JavaScript, React, Web Optimisation, Startups, Work Life Balance, etc. ā¤ļø JavaScrip