Trev Trev - 1 year ago 49
Javascript Question

Sending user to their browser's Home Page using Javascript

Is it possible to get a browser's home page using Javascript?

I'd like to place a link on a page that goes to the home page set in the browser.

Answer Source

EDIT: simplified answer

Identify browsers and:

  • Call window.home(); for all browsers

  • Call window.location.href = "about:home"; for IE

To do so you can use

The jQuery Browser Plugin is an addon for jQuery that makes it easy to uniquely identify your visitors' browsers.

Other solutions:

 <script language="javascript">
    function gohome(){
      if (typeof window.home == 'function'){ // The rest of the world
      } else if (document.all) { // For IE 
        window.location.href = "about:home";
      } else {
        document.write("<p>Please click on your browser's Home

This is via this website. The poster states that there are issues to target Safari. This can be fixed using this other website.

Using the CSS tricks explained there you can then do:

<script type="text/javascript">
   isSafari3 = false;
   if(window.devicePixelRatio) isSafari3 = true;

and use this in the script above to call the correct function:

if (typeof window.home == 'function' || isSafari3)