使用 Javascript 将用户发送到浏览器的主页 [英] Sending user to their browser's Home Page using Javascript

查看:29
本文介绍了使用 Javascript 将用户发送到浏览器的主页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用 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.

推荐答案

简化答案

识别浏览器并:

  • 调用window.home();适用于所有浏览器

  • Call window.home(); for all browsers

调用 window.location.href =关于家庭";对于 IE

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

为此,您可以使用 http://jquery.thewikies.com/browser/

jQuery 浏览器插件是一个插件对于 jQuery,它可以很容易地唯一标识您的访问者的浏览器.

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>

这是通过本网站.海报指出,针对 Safari 存在问题.这可以使用其他网站解决.

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

使用那里解释的 CSS 技巧,您可以执行以下操作:

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)

这篇关于使用 Javascript 将用户发送到浏览器的主页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆