我们如何使用JavaScript(或jQuery)更改在浏览器状态栏中显示的文本?
我们如何使用JavaScript(或jQuery)更改在浏览器状态栏中显示的文本?
这可以实现。Google搜索正在这样做,当您将鼠标悬停在Google链接上时,状态栏会显示底层网站:
然而当你点击它时,它会带你到一个依赖于位置和用户代理的URL,看起来像 https://www.google.com.sg/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0CC8QFjAAahUKEwi4lP-Z4_rIAhVLk5QKHXRLAe8&url=https%3A%2F%2Fwww.example.com%2F&usg=AFQjCNFEbIRqDC65KFpmuak0aXKmnzjKVQ&bvm=bv.106923889,d.dGo
。该URL在重定向到https://www.example.com
之前进行了Google跟踪等操作。你可以使用“保留日志”和网络检查器轻松测试此操作。
<a href="http://.# this is p̴̵̶͕͓͔͕͓͔͕͓͔͕͓͔͕͓͔͕͓͔͕͓͔͕͓͔͕͓͔͕͓͔͕͓͔͕͓͔͕͓͔͕͓͔͕͓͔̖͕͓̖̱̲̳̖̖̖̖̖̖̖͕͓͔̖͕͓͔̖͕͓͔̖͕͓͔̖͕͓͔̖͕͓͔̖͕͓͔̖͕͓͔̖̐̑̓̐̑̓̐̑̓̐̑̓̐̑̓̐̑̓̐̑̓̐̑̓̐̑̓̐̑̓̐̑̓̐̑̓̐̑̓̐̑̓̐̑̓̑̒̓̔̐̒̓̔̒̓̔̒̓̔̒̓̔̒̓̔̒̓̔̒̓̔̒̓̔̒̓̔̐̑̓̑̒̓̔̐̑̓̑̒̓̔̐̑̓̑̒̓̔̐̑̓̑̒̓̔̐̑̓̑̒̓̔̐̑̓̑̒̓̔̐̑̓̑̒̓̔̐̑̓̓̓̓̓̓̓̑̒̓̔̕̚̕̚̕̚̕̚̕̚̕̚̕̚̕̚̕̚͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜͜owerful because ━Σ(゚Д゚|||)━ symbols !@)(*#&$^%</even htlm> or lorem ipsum in all scripts Лорем ипсум Lorem存有 ငါ့ရဲ့ဇာတ်မြင့် घरՏուն Дома ലോറെൻ ഇപ്സം درமுகப்புЛорем ипсумలోלורם איפסוםరెం ఇప్సమ్ მთავარი હોમ לורם איפסוםלורם איפסום Forsíða Loremのイプサム ಮುಖಪುಟ ទំព័រដើម 가 lorem ipsum의 ຫນ້າທໍາອິດ Տուն আর্কাইভ">Hover this link (do not click) and observe the browser's status bar.</a>
Chrome的输出(点击图像放大):(v46.0.2490.80 m)
火狐浏览器输出:(v42.0) IE的输出:(v11.0.9600.17905更新版本11.0.21(KB3065822))Opera的输出:(v33.0.1990.58稳定版)
Seamonkey的输出:(v2.38)
Avant的输出:(v Ultimate 2015 build 28)
Torch的输出:(v42.0.0.10546)
百度的输出:(v43.19.1000.119)Maxthon的输出:(v4.4.8.1000)
#
(片段标识符)并非必要。浏览器也会将像 http://some.message.here./and_more_message_here
这样的文本视为有效的URL。根据浏览器不同,更奇怪的字符串也可能被视为有效。
<a href="http://a.b.c.d/test_symbols_!#$%^&*()[]{};:'".,//=+``~">
(Chrome, FireFox, IE, SM, Torch, Baidu, Maxthon, Avant IE11, Avant IE Compat, Avant Chrome, Avant Firefox.)
(列出了有预期输出的浏览器名称,对于没有状态栏输出的浏览器名称进行了删除线标记(“example”),对于输出/行为不符合预期的浏览器名称进行了下划线标记(“e̲x̲a̲m̲p̲l̲e̲”)。使用与上述浏览器版本相同的浏览器版本进行测试。)
<a href="http://a.b.c.d/test some spaces">
(Chrome, FireFox, I̲E̲, SM, Torch, B̲a̲i̲d̲u̲, M̲a̲x̲t̲h̲o̲n̲, A̲v̲a̲n̲t̲ I̲E̲ ̲1̲1̲, A̲v̲a̲n̲t̲ I̲E̲ ̲C̲o̲m̲p̲a̲t̲, Avant Chrome, Avant Firefox.)
<a href="http://test some . spaces in domain part/a_b_c_d_e">
(C̲h̲r̲o̲m̲e̲, FireFox, I̲E̲, SM, Torch, B̲a̲i̲d̲u̲, M̲a̲x̲t̲h̲o̲n̲, A̲v̲a̲n̲t̲ I̲E̲ ̲1̲1̲, Avant IE Compat, A̲v̲a̲n̲t̲ C̲h̲r̲o̲m̲e̲, Avant Firefox)
<a href="http://test some . spaces in domain part without slash">
(C̲h̲r̲o̲m̲e̲, FireFox, I̲E̲, SM, Torch, B̲a̲i̲d̲u̲, M̲a̲x̲t̲h̲o̲n̲, A̲v̲a̲n̲t̲ I̲E̲ ̲1̲1̲, Avant IE Compat, A̲v̲a̲n̲t̲ C̲h̲r̲o̲m̲e̲, Avant Firefox)
<a href="http://test_without_slash_and_dots">
(Chrome, FireFox, IE, SM, Torch, Baidu, Maxthon, Avant IE11, Avant IE Compat, Avant Chrome, Avant Firefox)
<a href="http://a.b.c:port_with_letters_test">
(Chrome, FireFox, IE, SM, Torch, Baidu, Maxthon, Avant IE11, Avant IE Compat, Avant Chrome, Avant Firefox)
<a href="http://double.http.test">
(Chrome, FireFox, IE
<a onclick="return false" href="http://some.message.here./and_more_message_here">this link will not load</a>
或者:
<a onclick="return f()" href="http://some.message.here./and_more_message_here">this link will not load</a>
<script>
function f() {
return false;
}
</script>
上述两个代码片段已在Chrome、FireFox、IE、SM、Torch、百度、傲游、Avant IE11、Avant IE Compat、Avant Chrome和Avant Firefox上测试通过。
window.location
或者 window.open
来模拟 a href
的行为。它可以内联完成:(在线测试)。<!doctype html>
<a onclick="location='http://example.org'; return false" href="https://some.message.here./and_more_message_here">same tab</a>
<br><a onclick="window.open('http://example.org'); return false" href="https://some.message.here./and_more_message_here">new tab</a>
或者使用 return func()
: (在线测试)
<!doctype html>
<a onclick="return f1()" href="http://some.message.here./and_more_message_here">same tab 2</a>
<br><a onclick="return f2()" href="http://some.message.here./and_more_message_here">new tab 2</a>
<script>
function f1() {
location = 'http://example.org';
return false;
}
function f2() {
open('http://example.org');
return false;
}
</script>
或者使用setTimeout
内联方式:(在线测试)
<!doctype html>
<a onclick="setTimeout(function(){location='http://example.org';},1); return false" href="https://some.message.here./and_more_message_here">same tab 3</a>
<br><a onclick="setTimeout(function(){window.open('http://example.org');},1); return false" href="http://some.message.here./and_more_message_here">new tab 3 (doesn't work on Avant IE11 and Avant IE Compat if this link is HTTP; works if it is HTTPS or FTP)</a>
setTimeout
和return func()
:(在线测试)<!doctype html>
<a onclick="return f1()" href="http://some.message.here./and_more_message_here">same tab 4</a>
<br><a onclick="return f2()" href="http://some.message.here./and_more_message_here">new tab 4 (doesn't work on Avant IE11 and Avant IE Compat if this link is HTTP; works if it is HTTPS or FTP)</a> <!-- hadn't tested this with sourcepage=HTTP. only tested with sourcepage=HTTPS and sourcepage=localwebpage -->
<script>
function f1() {
setTimeout(function() {
location = 'http://example.org';
}, 1);
return false;
}
function f2() {
setTimeout(function() {
open('http://example.org');
}, 1);
return false;
}
</script>
不必使用jQuery来做到这一点:
<script>
function writetostatus(input){
window.status=input
return true
}
</script>
然而,大多数更新的浏览器会防止您使用JavaScript设置状态栏中的文本。
针对IE浏览器的简单提示:
在IE6及其之前版本中,您可以进行以下操作:
window.status = "Hello, I'm a custom status bar note.";
回答一个10年前的问题。如果想要隐藏链接指向的位置,我使用这个函数。
<script>
function go2(hell){ window.location=hell; }
</script>
and the links will be like this :
<a href="#" onclick="go2('www.somewhere.net/page.html')">my link</a>
使用
window.status = "无论你想要的内容"