How do I hide the address bar on iPhone?

前端 未结 11 917
情话喂你
情话喂你 2020-12-02 12:37

How do I hide the address bar on iPhone?

I tried two different methods so far:

  • The scroll down one pixel trick with JavaScript on page load

11条回答
  •  [愿得一人]
    2020-12-02 12:56

    I think it will never be solved unless the content is more than the browser window.

    Here is some code that will hide the URL on load, on orientation change, and on a touchstart (the touchstart should only be used if you have a persistent hidden URL, which is a whole other can of worms - if you don't, remove that part of the script).

    if( !window.location.hash && window.addEventListener ){
        window.addEventListener("load", function() {
            setTimeout(function(){
                window.scrollTo(0, 0);
            }, 0);
        });
        window.addEventListener( "orientationchange",function() {
            setTimeout(function(){
                window.scrollTo(0, 0);
            }, 0);
        });
        window.addEventListener( "touchstart",function() {
             setTimeout(function(){
                 window.scrollTo(0, 0);
             }, 0);
         });
    }
    

提交回复
热议问题