Disable Android Chrome shutdown function

I created a small HTML5 web application for my company.

This application displays a list of items and everything is working fine.

The application is mainly used on Android and Chrome phones as a browser. In addition, the site is saved on the main screen, so Android controls the entire application ( using WebView, I think ).

Chrome Beta (and I also think Android System WebView) has added the "pull down to refresh" function ( See this link, for example ).

This is a convenient function, but I was wondering if it can be disabled using the meta tag (or javascript), because the update can be easily called by the user while navigating the list, and the whole application restarts.

It is also a feature not required by the application.

I know that this feature is still only available in the beta version of Chrome, but I have the feeling that it also lands on a stable application.

Thank!

Edit: I uninstalled the beta version of Chrome, and the link attached to the main screen now opens stable Chrome. So anchor links start with Chrome, not webview.

Edit: Today (2015-03-19) the transition to upgrade has reached stable chrome.

Edit: from @Evyn answer I follow this link and got this javascript / jquery code that works.

var lastTouchY = 0; var preventPullToRefresh = false; $('body').on('touchstart', function (e) { if (e.originalEvent.touches.length != 1) { return; } lastTouchY = e.originalEvent.touches[0].clientY; preventPullToRefresh = window.pageYOffset == 0; }); $('body').on('touchmove', function (e) { var touchY = e.originalEvent.touches[0].clientY; var touchYDelta = touchY - lastTouchY; lastTouchY = touchY; if (preventPullToRefresh) { // To suppress pull-to-refresh it is sufficient to preventDefault the first overscrolling touchmove. preventPullToRefresh = false; if (touchYDelta > 0) { e.preventDefault(); return; } } }); 

As @bcintegrity pointed out, I hope for a solution to the site’s manifest (and / or meta tag) in the future.

In addition, suggestions for the above code are welcome.

+120
android html html5 google-chrome meta-tags
Mar 12 '15 at 11:10
source share
14 answers

The default action for the pull-to-refresh effect can be effectively prevented by doing one of the following:

  1. preventDefault some parts of the touch sequence, including any of the following (in order from most destructive to least destructive):
    • but. All sensory stream (not perfect).
    • b. All upper super-fast sensory movements.
    • from. First overrun sensory move.
    • e. The first touch with the top scroll only when 1) the initial touch occurred when the page offset y was zero, and 2) the touch would move the top scroll.
  2. Applying " touch-action: none " to touch-action: none targeted elements, where appropriate, disabling the default action (including pull-to-refresh) of a touch sequence.
  3. Applying " overflow-y: hidden " to the body element, using a div for scrollable content, if necessary.
  4. Disabling an effect locally using chrome://flags/#disable-pull-to-refresh-effect ).

To learn more

+140
Mar 28 '15 at 4:26
source share

A simple solution for 2019+

Chrome 63 (released December 5, 2017) added a css property to help with just that. Read this guide from Google to get an idea of ​​how to deal with it.

Here is their TL: DR

The CSS property of overscroll behavior allows developers to override the default browser overflow scroll behavior when they reach the top / bottom of the content. Use cases include disabling the pull-to-refresh function on a mobile device, eliminating the effects of glowing when scrolling excessively and having a rubber band, and also preventing scrolling of the page if it is below the modal / overlay.

To make it work, all you have to add is in your CSS:

 body { overscroll-behavior: contain; } 

It is currently only supported by Chrome, Edge and Firefox, but I'm sure Safari will add it soon, as they seem to be fully compatible with service workers and the future PWA.

+69
Dec 08 '17 at 7:49
source share

At the moment, you can disable this function only with chrome: // flags / # disable-pull-to-refresh-effect - open directly from your device.

You can try to catch touchmove events, but the chances are very subtle to achieve an acceptable result.

+15
Mar 20 '15 at 16:31
source share

I use MooTools, and I created a class to disable updates on the target element, but its essence (native JS):

 var target = window; // this can be any scrollable element var last_y = 0; target.addEventListener('touchmove', function(e){ var scrolly = target.pageYOffset || target.scrollTop || 0; var direction = e.changedTouches[0].pageY > last_y ? 1 : -1; if(direction>0 && scrolly===0){ e.preventDefault(); } last_y = e.changedTouches[0].pageY; }); 

All we do is find the direction y of the touch button, and if we move down the screen and the target scroll is 0, we will stop this event. Therefore, the update is not updated.

This means that we shoot every “move” that can be costly, but this is the best solution I've found so far ...

+8
Mar 27 '15 at 14:16
source share

Angularjs

I successfully disabled it using this AngularJS directive:

 //Prevents "pull to reload" behaviour in Chrome. Assign to child scrollable elements. angular.module('hereApp.directive').directive('noPullToReload', function() { 'use strict'; return { link: function(scope, element) { var initialY = null, previousY = null, bindScrollEvent = function(e){ previousY = initialY = e.touches[0].clientY; // Pull to reload won't be activated if the element is not initially at scrollTop === 0 if(element[0].scrollTop <= 0){ element.on("touchmove", blockScroll); } }, blockScroll = function(e){ if(previousY && previousY < e.touches[0].clientY){ //Scrolling up e.preventDefault(); } else if(initialY >= e.touches[0].clientY){ //Scrolling down //As soon as you scroll down, there is no risk of pulling to reload element.off("touchmove", blockScroll); } previousY = e.touches[0].clientY; }, unbindScrollEvent = function(e){ element.off("touchmove", blockScroll); }; element.on("touchstart", bindScrollEvent); element.on("touchend", unbindScrollEvent); } }; }); 

It is safe to stop viewing as soon as the user scrolls down, since the pull to update has no chance of being called.

Similarly, if scrolltop > 0 , the event will not be fired. In my implementation, I bind the touchmove event to touchstart only if scrollTop <= 0 . I disconnect it as soon as the user scrolls down ( initialY >= e.touches[0].clientY ). If the user scrolls ( previousY < e.touches[0].clientY ), I call preventDefault() .

This saves us from viewing scroll events unnecessarily, but blocks cross-checking.

JQuery

If you use jQuery, this is an unverified equivalent. element is a jQuery element:

 var initialY = null, previousY = null, bindScrollEvent = function(e){ previousY = initialY = e.touches[0].clientY; // Pull to reload won't be activated if the element is not initially at scrollTop === 0 if(element[0].scrollTop <= 0){ element.on("touchmove", blockScroll); } }, blockScroll = function(e){ if(previousY && previousY < e.touches[0].clientY){ //Scrolling up e.preventDefault(); } else if(initialY >= e.touches[0].clientY){ //Scrolling down //As soon as you scroll down, there is no risk of pulling to reload element.off("touchmove"); } previousY = e.touches[0].clientY; }, unbindScrollEvent = function(e){ element.off("touchmove"); }; element.on("touchstart", bindScrollEvent); element.on("touchend", unbindScrollEvent); 

Naturally, the same can be achieved with pure JS.

+5
Aug 07 '15 at 12:21
source share

After many hours of trying, this solution works for me

 $("html").css({ "touch-action": "pan-down" }); 
+5
Mar 31 '17 at 8:15
source share

Simple javascript

I implemented using standard javascript. Simple and easy to use. Just insert and it works great.

 <script type="text/javascript"> //<![CDATA[ window.addEventListener('load', function() { var maybePreventPullToRefresh = false; var lastTouchY = 0; var touchstartHandler = function(e) { if (e.touches.length != 1) return; lastTouchY = e.touches[0].clientY; // Pull-to-refresh will only trigger if the scroll begins when the // document Y offset is zero. maybePreventPullToRefresh = window.pageYOffset == 0; } var touchmoveHandler = function(e) { var touchY = e.touches[0].clientY; var touchYDelta = touchY - lastTouchY; lastTouchY = touchY; if (maybePreventPullToRefresh) { // To suppress pull-to-refresh it is sufficient to preventDefault the // first overscrolling touchmove. maybePreventPullToRefresh = false; if (touchYDelta > 0) { e.preventDefault(); return; } } } document.addEventListener('touchstart', touchstartHandler, false); document.addEventListener('touchmove', touchmoveHandler, false); }); //]]> </script> 
+4
04 Feb '16 at 23:19
source share

The best solution for pure CSS:

 body { width: 100%; height: 100%; display: block; position: absolute; top: -1px; z-index: 1; margin: 0; padding: 0; overflow-y: hidden; } #pseudobody { width:100%; height: 100%; position: absolute; top:0; z-index: 2; margin: 0; padding:0; overflow-y: auto; } 

Watch this demo: https://jsbin.com/pokusideha/quiet

+3
Feb 25 '17 at 18:11
source share

I find that setting

body CSS overflow-y: hidden is the easiest way. If you want to have a scrollable application page, you can simply use the div container with scroll functions.
+3
Sep 01 '17 at 4:33 on
source share

In a couple of weeks, I found out that the javascript function that I used to disable the Chrome update action will no longer work. I decided to solve this:

 $(window).scroll(function() { if ($(document).scrollTop() >= 1) { $("html").css({ "touch-action": "auto"} ); } else { $("html").css({ "touch-action": "pan-down" }); } }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> 
+2
Mar 01 '17 at 15:04
source share

Note that overflow-y is not inherited, so you need to set it to ALL block elements.

You can do this with jQuery, simply:

  $(document.body).css('overflow-y', 'hidden'); $('*').filter(function(index) { return $(this).css('display') == 'block'; }).css('overflow-y', 'hidden'); 
+1
May 4 '16 at 11:44
source share

What I did was add the following touchstart and touchend / touchcancel :

 scrollTo(0, 1) 

Since chrome does not scroll unless it is in scrollY position 0 , this will prevent chrome from executing for the update.

If it still does not work, try to do it when the page loads.

0
Oct 20 '17 at 9:39 on
source share

Pure js solution.

 // Prevent pull refresh chrome var lastTouchY = 0; var preventPullToRefresh = false; window.document.body.addEventListener("touchstart", function(e){ if (e.touches.length != 1) { return; } lastTouchY = e.touches[0].clientY; preventPullToRefresh = window.pageYOffset == 0; }, false); window.document.body.addEventListener("touchmove", function(e){ var touchY = e.touches[0].clientY; var touchYDelta = touchY - lastTouchY; lastTouchY = touchY; if (preventPullToRefresh) { // To suppress pull-to-refresh it is sufficient to preventDefault the first overscrolling touchmove. preventPullToRefresh = false; if (touchYDelta > 0) { e.preventDefault(); return; } } }, false); 
0
Oct 25 '17 at 12:21
source share

I solved the dropdown menu problem with this:

 html, body { width: 100%; height: 100%; overflow: hidden; } 
0
Jul 10 '19 at 9:31 on
source share



All Articles