31

Is there any way to create Internet shortcut files that will work with all operating systems (including Mac, Windows, and Linux)? I often switch between Windows and Linux, and I haven't yet found a way to create an internet shortcut file (on the desktop or in a local folder) that is compatible with all operating systems.

Anderson Green
  • 6,452
  • 15
  • 52
  • 76
  • 1
    2018 update: macs can handle .url files, though they default to Safari. Linux and Android do not handle .url. https://chrome.google.com/webstore/detail/webcuts/kehckhdcknjaadegmihldoedmdfmpcmk can make xplatform links for you. – Ray Foss Dec 11 '17 at 18:34
  • [Quite related question here](https://superuser.com/q/277186/910769), also proposing [html-refresh](https://superuser.com/a/1340296/910769), as well as some bash scripts, which can be used in windows with a powershell, [MinGW](https://sourceforge.net/projects/mingw/), [WSL](https://ubuntu.com/wsl) or [Cygwin](https://cygwin.com/)/[MSYS2](http://www.msys2.org/). `.desktop`-Files might not fit as well. – Cadoiz Oct 20 '21 at 08:33

4 Answers4

31

I found a reasonable cross-platform solution. This HTML document could be used as a shortcut to stackoverflow.com, and it would immediately redirect to that site when opened from the desktop:

<html>
<body>
<script type="text/javascript">
    window.location.href = "http://stackoverflow.com"; //change this to the URL
                                                       //you want to redirect to
</script>
</body>
</html>
Anderson Green
  • 6,452
  • 15
  • 52
  • 76
  • 1
    this is such a fantastically simple solution... thank you – Nicholas Franceschina Jan 29 '13 at 00:27
  • 24
    Why not use `` in the `` instead of relying on javascript? – Evan Mattson Sep 11 '14 at 00:23
  • While most browsers will accept that bare-minimum oneliner `.html file`, @Evan or the reader can consider [this more exhaustive answer](https://superuser.com/a/1031155/910769). [My answer here](https://superuser.com/a/1682615/910769), where I provide a script that automatically generates `.html`-Files like this, builds upon that. – Cadoiz Oct 21 '21 at 10:35
  • Note that the file extension must be `.html` for this to work. – user2340939 Mar 14 '23 at 15:52
19

Credit to Evan Mattson from the comments.

From W3C, Technique H76: Using meta refresh to create an instant client-side redirect:

The objective of this technique is to enable redirects on the client side without confusing the user. Redirects are preferably implemented on the server side (see SVR1: Implementing automatic redirects on the server side instead of on the client side (SERVER) ), but authors do not always have control over server-side technologies.

Example from the link above:

<html xmlns="http://www.w3.org/1999/xhtml">    
  <head>      
    <title>The Tudors</title>      
    <meta http-equiv="refresh" content="0;URL='http://thetudors.example.com/'" />    
  </head>    
  <body> 
    <p>This page has moved to a <a href="http://thetudors.example.com/">
      theTudors.example.com</a>.</p> 
  </body>  
</html>

Basically, a refresh is done after zero seconds (immediately) to the specified URL, before the page content is loaded, and without JavaScript.

Cadoiz
  • 519
  • 3
  • 10
tavnab
  • 290
  • 3
  • 6
  • You can consider [my answer here](https://superuser.com/a/1682615/910769), where I provide a script that automatically generates `.html`-Files like this. – Cadoiz Oct 21 '21 at 10:33
  • You can also consider/compare [this answer](https://superuser.com/a/1340296/910769) – Cadoiz Oct 25 '21 at 10:00
15

You can define a file named as following - MyInternetShortcut.url.

It's content should be:

[InternetShortcut]
URL=https://my.amazingsite.com/

This works on Windows and macOS.

Royi
  • 519
  • 1
  • 11
  • 24
  • 1
    Maybe your Linux. Opens in text editor on my Linux Mint 17.3 Mate system. – kreemoweet Feb 10 '19 at 19:10
  • I have Linux Mint 18.3 and it doesn't work as well. I guess my memory tricked me. It does work on macOS and Windows. I will update the answer. Thank You. – Royi Feb 10 '19 at 20:58
  • 1
    Works well on MacOS Catalina 10.15.6 – Bishwas Mishra Jul 26 '20 at 13:59
  • It does work well with many (graphical, modern) Linux distros - and if not, most usual browsers can intrepret it, so you can open the `xyz.url` with it. I wrote [a script provided here](https://superuser.com/a/1682971/910769) that automatically generates url-links like proposed by this answer. – Cadoiz Oct 21 '21 at 10:30
0

For ease of use, I wrote a script to generate .url-files like Royi suggested in his answer. Making this script runnable with e.g. chmod +x url_linkscript.sh makes things even more handy. This file contains:

#!/bin/bash
echo "[InternetShortcut]
URL=$1" > "$2"

You can then run it like this: $ url_linkscript.sh "https://my.amazingsite.com/" "result.url". (Depending on your link and file name, this usually also works without the quotes ".)

Cadoiz
  • 519
  • 3
  • 10
  • This answer could be extended by a `.bat`-script that does the same thing from within windows (without the need for a bash compatibility layer). – Cadoiz Oct 21 '21 at 10:28