views:

458

answers:

3

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.

A: 

For FF and the like: window.home();

For IE: location = "about:home";

Kyle Rozendo
A: 

Not sure if there is a cross-browser solution. In IE you can use the HomePage behavior and call navigateHomePage.

jeffamaphone
+1  A: 

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 http://jquery.thewikies.com/browser/

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
        window.home();
      } else if (document.all) { // For IE 
        window.location.href = "about:home";
      } else {
        document.write("<p>Please click on your browser's Home
button.</p>");
      }
    }
  </script>

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;
</script>

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

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