Home >Web Front-end >JS Tutorial >Implementation principle and code of automatically hiding the address bar of mobile browsers through JS_javascript skills
Everyone opens Baidu and Taobao through the browser that comes with their mobile phone. After the homepage is loaded, the address bar at the top of the page will be automatically hidden. In addition, these websites are optimized for mobile browsers. At first glance, it is really difficult to distinguish them. Is this a WEB APP or a Native App? The picture on the left below shows the homepage of Taobao opened through Safari. If it weren’t for the browser toolbar underneath, it would really look like a Native App. In fact, it has an address. Drag it down and you will see the address bar, as shown in the picture on the right below.
How to hide the browser address bar? Baidu, there is a lot of information, it is very simple. It mainly uses the window.scrollTo() method to scroll the current page up on the screen, causing the address bar to exceed the field of view, as follows:
But if your web page contains a lot of content and exceeds the height of the screen, the address bar will be automatically hidden;
How to hide the address bar when there is less content? Before scrolling, the program needs to dynamically set the height of the body. Add the following code: