Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell if webpage is running in chrome application shortcut mode

We can create application shortcut in google Chrome. I would like to display a different layout when my web page is running in application shortcut mode - which basically is running in a separate standalone window.

Is there a way to tell if web page is running in application shortcut mode?

Right now I am testing if the window can be re-sized by JavaScript - assuming that it is running in application shortcut mode if the window can be re-sized.

I am wondering if there is a better way to do this.

[Update] Basically we want to know if the webpage is running in a single window or running in one tab of a window.

like image 798
Qiusheng Avatar asked Nov 02 '22 20:11

Qiusheng


1 Answers

I've just googled a bit and found this site: http://blog.kenneth.io/blog/2010/05/04/desktop-icons-in-google-chrome/

You can see this <meta> element in the first code block:

<meta name="application-url" content="http://www.example.com"/>

I haven't found any reliable and offcial documentation* yet, but it seems to work in a quick test I've just made.

In that way, you could pass an extra query string to your URI which only gets called when opening from a pinned (taskbar|desktop) short cut.

*) This <meta> element is also unofficially metioned here: Page Meta Properties - mozilla f1.



How can it be used?

  • Create a new HTML document:

<html>
  <head>
    <meta charset="utf-8" />
    <meta name="application-url" content="http://www.exaple.com?shortcut=true" />

    <title>Test</title>
  </head>

  <body>
    Test
  </body>
</html>
  • Now, open this document in Google chrome (works also with local file system!).
  • Create a taskbar and/or desktop shortcut via Chrome's Tools menu.
  • Chrome will open another window with the original URI. This is possibly a bug.
    But if you use the shortcut, Chrome will open the URI provided in the <meta> tag (here: http://www.exaple.com?shortcut=true).
like image 68
ComFreek Avatar answered Nov 09 '22 12:11

ComFreek