How to create an index.html page with a web address

In Windows there is an option to allow you create an index.html file which opens a specific web address when clicked on it. How can I create a similar file in Mac?

I want to have a file called index.html and when clicked, a web address www.example.com should open in the default browser.


Solution 1:

If you are determined to use an HTML file, you can create one with a text editor (e.g. the built-in TextEdit; make sure you use the Plain Text view rather than the Rich Text which is the default).

Your HTML file should contain a so-called meta-refresh tag for this:

<meta http-equiv="refresh" content="0; url=http://www.example.com/" />

The page will automatically redirect upon loading.

Alternatively, because this sounds like an XY-problem: create a shortcut to the page on your Desktop, as described by Joonas.

Solution 2:

Drag favicon from a browser to the desktop or into Finder.

This creates a .webloc file, which will open in the default browser when opened.

In some sites you may have to drag the lock icon, info icon... or whatever is on the immediate left from the site url in the address bar. You may also try selecting the url and dragging that, but that doesn't work in Chrome at least, I believe.

Works in Safari, Chrome and Firefox


I should also mention that you should be able to do this with any link elements in a website as well. It may not work if javascript is used load things when the link is clicked.