Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript - create desktop link programmatically

Tags:

javascript

Is there a way to programmatically create a desktop link for my webpage?

like image 848
Denis Kulagin Avatar asked Nov 22 '12 09:11

Denis Kulagin


3 Answers

Not from Javascript, but there is a trick to let the users do it. It is more of an interaction design technique rather than programming technique but I'll write it maybe someone googles this question and finds it useful.

Make an icon on your page with a text under it. Then ask the user to drag this icon to their desktop. The icon should be embedded in an anchor tag <a> with the href attribute pointing to your website. The text under the icon should be the same as the <title> tag of your page. The browsers make an icon when the user drags an anchor link from a page to a folder, desktop or bookmark bar. The text that the browsers assign this shortcut or link is usually the <title> of the page. Remember that the icon should be set as the background of the element so that the browser doesn't save the image instead of making a new link. It would be even better if this icon is the same as the favicon of your website.

To demonstrate this technique here is some code:

<p>You can make a shortcut to www.mysite.com by dragging this icon to your desktop or bookmark bar: </p>
<a href="https://www.example.com">
  <div id="icon" style="background-image:url('favicon.png');width:32px;height:32px;"></div>
  <div id="title">www.example.com</div>
</a>

Like a native app:

In Chrome users can go to Menu > More tools > Create application shortcut... and create a borderless shortcut to your site that looks like an app. Something similar can be done in Android, iOS and also Firefox on Android.

like image 124
AlexStack Avatar answered Oct 21 '22 19:10

AlexStack


This is not possible with browser scripts such as JavaScript. It is a security feature. I'm sure you can appreciate why people would not want webpages to be able to access your local file system.

Imagine that instead of drowning in popup windows, we would be drowning in files created by spammy/scammy webpages. I'm not saying that your site is spammy or scammy, just trying to put this into perspective :)

You could quite easily create a sort of tutorial for your users on how to create a shortcut or add your page to their bookmarks taking into consideration that users may be using different browsers, but if you cover the major browsers, Chrome, Firefox and IE, I'm sure your users will have no problem following your instructions.

like image 3
Lix Avatar answered Oct 21 '22 19:10

Lix


From JavaScript, running on a webpage?

No.

like image 1
Quentin Avatar answered Oct 21 '22 20:10

Quentin