Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect standalone mode on old chrome version

According to this article, display-mode: standalone only can detect on M48 or newer version. Is there any way to detect the mode on older version?

like image 582
Hoang Trung Avatar asked Apr 06 '18 03:04

Hoang Trung


2 Answers

Although it's not a direct answer but it's offering a workaround.

As much as I understand the article, you can configure your website (in the manifest.json) to open with querystring (for example) if it opens from the homescreen. So you can set a flag on the DOM - let's say add class to the body tag. In this way you can detect in eitgher css or js if you run in standalone mode.

For example:

var isStandalone = false;
if (location.search.indexOf('standalone=true') > -1) {
  isStandalone = true;
  document.body.classList.add('standalone-mode');
}

// from now on you can check if you run in standalone by checking 'isStandalone' param.
header {
  background: red;
}

/* this is a style for standalone mode only */
body.standalone header {
  background: green
}
like image 38
Mosh Feu Avatar answered Nov 12 '22 22:11

Mosh Feu


No this is not possible. Check this article

@supports for display-mode is only supported starting with Chrome 48.

like image 63
Sandwell Avatar answered Nov 12 '22 20:11

Sandwell