Sending user to their browser's Home Page using Javascript

后端 未结 5 1097
庸人自扰
庸人自扰 2020-11-28 15:15

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.

5条回答
  •  自闭症患者
    2020-11-28 15:32

    Default home page (default new tab) URL:

    Google Chrome:

    https://www.google.com/_/chrome/newtab
    

    Firefox and IE:

    about:home
    

    Opera:

    opera:speeddial
    

    Safari:

    http://livepage.apple.com
    

    To find out the default home page URL of your browser, go to your home page and type location.href in the console. Note that the browser might redirect you to your locale, so you'll need to find out the page before redirection (it happens on Chrome).


    If you're using this browser detection code you can use this one-liner to get the correct url:

    var homepageurl = browser == 'gc' ? 'https://www.google.com/_/chrome/newtab' : browser == 'op' ? 'about:speeddial' : browser=='sa' ? 'http://livepage.apple.com' : 'about:home'
    

    Browser detection code JSFiddle: https://jsfiddle.net/oriadam/ncb4n882/

提交回复
热议问题