Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 930
Trev Avatar asked Sep 02 '09 18:09

Trev


People also ask

How do I move one HTML page to another using JavaScript?

Answer: Use the JavaScript window. location Propertylocation property to make a page redirect, you don't need any jQuery for this. If you want to redirect the user from one page to another automatically, you can use the syntax window. location. replace("page_url") .

How do you go to a website using JavaScript?

Press the Ctrl + U keyboard shortcut. Right-click an empty area on the web page and select the View page source or similar option in the pop-up menu.

How does JavaScript interact with browser?

The way JavaScript works is interesting. Inside a normal Web page you place some JavaScript code (See How Web Pages Work for details on Web pages). When the browser loads the page, the browser has a built-in interpreter that reads the JavaScript code it finds in the page and runs it.


1 Answers

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)
like image 115
marcgg Avatar answered Sep 21 '22 15:09

marcgg