【问题标题】:Change link in status bar更改状态栏中的链接
【发布时间】:2014-04-19 22:00:25
【问题描述】:

我正在寻找一种方法来更改浏览器状态栏中的链接,类似于 google 和 yahoo 用来显示其搜索结果的方法。这是我的示例代码

<html>
<head>
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
 </head>
<body>

<script type="text/javascript">
$(document).ready(function() {
  $('a').attr('orig_href', function() { return $(this).attr('href') })
    .attr('href', 'http://www.google.com')
    .click(function() {
        window.location.href = $(this).attr('orig_href');
        return false;
    });
});
</script>

  <p id="hello">Hello World</p>

  <div><a href="http://www.stackoverflow.com/">Link 2</a></div>
  <div><a href="http://meta.stackoverflow.com/">Link 3</a></div>
</body>
 </html>

当鼠标悬停在链接上时,状态栏一直是http://www.google.com。但是,这不是真正的网址。当我们左键单击一个链接时,浏览器将带入真正的 url(例如,stackoverflow.com)。这是我所期望的。

问题是,当我们右键单击并打开链接到新标签页时,浏览器会将我们带到错误的 url,即 google.com。

谁能指出应该怎么做,以便在新标签页中打开时,它会转到真正的 url (stackoverflow.com)?

非常感谢。

【问题讨论】:

标签: javascript jquery html statusbar


【解决方案1】:

试试这个:

<a href="http://meta.stackoverflow.com/" onmouseover="$(this).attr('href', 'http://www.google.com')" onmousedown="$(this).attr('href', 'http://meta.stackoverflow.com/')">Link 4</a>

也许不是最好的解决方案,但这项工作(不幸的是不在 JSfiddle 上)。

【讨论】:

  • 你太棒了!它在我的 Firefox 和 Google chrome 上完美运行。非常感谢
【解决方案2】:

为什么需要 JQuery 来覆盖 href 属性?删除脚本标签,你应该很高兴!

【讨论】:

  • 感谢 Martins 回答我的问题。否决票不是来自我,只是为了澄清。 MarOnii 的解决方案对我有用。再次感谢您:)
【解决方案3】:
$(document).ready(function() {
  $('a').attr('orig_href', function() { return $(this).attr('href') })
    .attr('href', 'http://www.google.com')
    .mousedown(function() {
        $(this).attr('href', $(this).attr('orig_href'));
        return false;
    });
});

好的,试试这个,抱歉我误解了这个问题。

【讨论】:

  • 当我更换它时,问题仍然存在。谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多