Javascript 如何隐藏浏览器中的状态栏?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4315029/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 11:52:06  来源:igfitidea点击:

How can i hide the status bar in the browser?

javascripthtmlstatusbar

提问by Simon Thomsen

I have a simple question, how can I hide a link in the status bar in my browser.

我有一个简单的问题,如何隐藏浏览器状态栏中的链接。

I've tried with this:

我试过这个:

<a href="http://www.sell.com/?referrer=225"
   onMouseOver="window.status='http://www.sell.com';
               return true" onMouseOut="window.status=''">Click here</a>

(Taken from a tutorial) But it doesn't work, if somebody would help me, I would be very happy! ;-)

(取自一个教程)但是它不起作用,如果有人能帮助我,我会很高兴!;-)

回答by Nick Craver

You can't (at least in current browsers), which is a good thing. It would help phishing attacks a great deal to disguise the link.

你不能(至少在当前的浏览器中),这是一件好事。伪装链接对网络钓鱼攻击有很大帮助。

回答by Dimitar Christoff

Since you are asking to do this in order to hide affiliation links, there may be a better way.

由于您要求这样做是为了隐藏从属链接,因此可能有更好的方法。

It makes far more sense to loop through all your links, say, under a broad $("a.out")selector, then get and store their real href into element storage, replace it with a dummy one (and the title attribute if you have to).

循环遍历所有链接更有意义,例如,在一个广泛的$("a.out")选择器下,然后获取它们的真实 href 并将其存储到元素存储中,将其替换为一个虚拟链接(如果需要,还可以使用 title 属性)。

You then attach a click event handler that stops the default event, reads back the original href and sets it as the location.href, effectively disguising the links to all that have js enabled.

然后附加一个 click 事件处理程序,它停止默认事件,读回原始 href 并将其设置为 location.href,有效地伪装所有启用了 js 的链接。

Eg code in mootools:

例如 mootools 中的代码:

(function() {
    var links = document.getElements("a.out");

    links.each(function(el) {
        // save original
        el.store("href", el.get("href"));
        // replace it.
        el.set("href", el.get("data-link"));

        el.addEvents({
            click: function(e) {
                e.stop();
                // console.log(e);

                document.location.href = this.retrieve("href");
            },
            contextmenu: function(e) {
                e.stop();
                // do something on right click so we dont get caught
                alert("hi");
            }
        });
    });
})();

Which works fine on this markup:

在此标记上运行良好:

<a href="http://www.energyhelpline.com/energy/rg_home.aspx?aid=107" rel="nofollow" class="out" title="Enegry savings" data-link="http://www.energyhelpline.com/">Swap Energy Provider</a><br />

<a href="http://www.moneysupermarket.com/link.asp?Source=MSE&Section=utils" rel="nofollow" class="out" title="Money supermarket" data-link="http://www.moneysupermarket.com/">Money Supermarket</a>

With data-link containing what we SHOW to end users instead.

数据链接包含我们向最终用户展示的内容。

回答by Wonkey Wizard

Here is some code that will hide your original link tread text in a browsers status bar area

这是一些将在浏览器状态栏区域中隐藏原始链接踏板文本的代码

Please note: not sure which browsers it works on but works fine in IE9

请注意:不确定它适用于哪些浏览器,但在 IE9 中工作正常

<a href="javascript:void(0);" onclick="location.href='http://www.google.com';return false;">If You Put Your Mouse Over This Text You Won't See Link In Status Bar Area</a>

When you run your mouse over the link, all you see in the status bar is javascript:void(0);

当您将鼠标移到链接上时,您在状态栏中看到的只是 javascript:void(0);

回答by StuperUser

You can set the text of the status bar using javascript with window.statusattribute. E.g. http://www.htmlite.com/JS017.php

您可以使用带有window.status属性的javascript 设置状态栏的文本。例如http://www.htmlite.com/JS017.php

If you REALLY need, to disable the status bar in a browser, you can get a copy of an open-source browser code base, remove all code for the status bar and redistribute it to your users, but I doubt this is what you mean/need.

如果您真的需要禁用浏览器中的状态栏,您可以获得开源浏览器代码库的副本,删除状态栏的所有代码并将其重新分发给您的用户,但我怀疑这就是您的意思/需要。

Why do you need to hide the link in the status bar? A security issue with not wanting to expose the URL could be dealt with in another way.

为什么需要隐藏状态栏中的链接?不想公开 URL 的安全问题可以用另一种方式处理。

回答by Georg Sch?lly

You can do this by using javascript for your link:

您可以通过为您的链接使用 javascript 来做到这一点:

Here's how:

下面是如何

function goToBing() {
  window.location.href = "http://bing.com";
}

and

<a href="http://google.com" onclick="goToBing();return false;">Link to Google</a>

As Nick Craver said, this doesn't work in all circumstances (control-click, middle-click etc.) but should work for you, because you don't relayon the javascript link.

正如 Nick Craver 所说,这并不适用于所有情况(控制单击、中键单击等),但应该对您有用,因为您不会在 javascript 链接上进行中继

回答by Mahn

Here's a way with javascript + jQuery that works with ctrl click, shift click, middle click, etc. It does break right click, but if the goal is to hide the link I guess that's not a big deal.

这是一种使用 javascript + jQuery 的方法,可与 ctrl 单击、shift 单击、中键单击等一起使用。它确实会中断右键单击,但如果目标是隐藏链接,我想这没什么大不了的。

I take no responsability whatsoever what you do with this though, I did this mostly for fun, but it does look pretty evil.

不管你对此做什么,我不承担任何责任,我这样做主要是为了好玩,但它看起来确实很邪恶。

JS:

JS:

$(document).ready(function() {
   $('a').each(function() {
       var address = $(this).attr('href');
       var element = $(this).contents().unwrap().wrap('<div/>').parent();
       element.data("hrefAddress", address).addClass("link");

       element.click(function() {               
           var newWindow = window.open(element.data("hrefAddress"), '_blank');
           newWindow.focus();
       });
   });
});?

CSS:

CSS:

.link {
    color: #00f;
    text-decoration: underline;
    cursor: pointer;
}

.link:hover {
    color: #00a;
}

HTML:

HTML:

<div>
    <a href="http://www.facebook.com">Facebook</a>
    <a href="http://www.bing.com">Google</a>
    <a href="http://www.yahoo.com">Yahoo</a>
    <a href="http://stackoverflow.com">Stack Overflow</a>
</div>?

JS Fiddle

JS小提琴