英文:
Hide or Manipulate URL in browser left-bottom side when mouse curser placed in ahref tag
问题
我想要隐藏、移除或操控浏览器左下角显示的URL,就像Google一样。
尝试使用JS:
<a href="https://example.com" onmouseover="window.status='google.com'; return true;" onmouseout="window.status=''; return true;">Example</a>
尝试使用CSS:
.no-tooltip:hover::after {
content: none !important;
}
<a href="http://example.com" class="no-tooltip">Link</a>
Google示例:
在Google中,当您将鼠标指针放在任何搜索结果或ahref标签上时,会显示如上所示的URL状态,但当您单击它或复制它时,您将找到不同的URL:
屏幕截图:
英文:
I want to hide, remove or manipulate URL display in left-bottom in browser like Google.
Trying with JS:
<a href="https://example.com" onmouseover="window.status='google.com'; return true;" onmouseout="window.status=''; return true;">Example</a>
Trying with CSS :
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-css -->
.no-tooltip:hover::after {
content: none !important;
}
<!-- language: lang-html -->
<a href="http://example.com" class="no-tooltip">Link</a>
<!-- end snippet -->
Google example :
In Google, when you place pointer in any search result or ahref tag it show URL Status like above screenshot but when you click it or copy it you will find different https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=&cad=rja&uact=8&ved=2ahUKEwizyLqk54X-AhWIUGwGHeqDA5EQFnoECCUQAQ&url=https%3A%2F%2Fexample.com%2F&usg=AOvVaw2g9Si57HiLP2X7LeNGKaHd
Screenshot :
答案1
得分: 1
你可以使用 event.preventDefault
阻止链接传播,然后使用 JavaScript 重定向到另一个页面。
这是一个简单的示例:
$(document).ready(function (){
$("a").click(function(event) {
event.preventDefault(); // 停止重定向
location.href="https://www.wikipedia.org";
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="link">
<a href="http://www.google.it">Google</a>
</div>
希望对你有帮助!
英文:
You can use event.preventDefault
to block link propagation and then redirect to another page with javascript.
Here's a simple example:
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-js -->
$(document).ready(function (){
$("a").click(function(event) {
event.preventDefault(); //stop the redirect
location.href="https://www.wikipedia.org";
});
});
<!-- language: lang-html -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="link">
<a href="http://www.google.it">Google</a>
</div>
<!-- end snippet -->
Hope i was helpful!
答案2
得分: 1
你不能改变 Window.status
。要实现所需的结果,你可以使用 location.href
或 location.replace
。
英文:
You cannot change Window.status
. To achive desire result, you can use location.href
or location.replace
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-js -->
var link = document.getElementById("my-link");
link.addEventListener("click", function(event) {
event.preventDefault(); // Prevent the default link behavior
// Change the href to the new URL
link.href = "https://www.example.com";
// Redirect to the new URL
//window.location.href = link.href;
window.location.replace(link.href);
});
<!-- language: lang-html -->
<a id="my-link" href="https://www.google.com" data-mc-cta="1" target="_blank">Click me!</a>
<!-- end snippet -->
To include left-clicks, right-clicks and contextmenu
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-js -->
var link = document.getElementById("my-link");
function redirectLink(event) {
event.preventDefault(); // Prevent the default link behavior
link.href = "https://www.example.com"; // Change the href to the new URL
window.location.replace(link.href); // Redirect to the new URL
}
// Listen for left-click and contextmenu events
link.addEventListener("click", redirectLink);
link.addEventListener("contextmenu", redirectLink);
<!-- language: lang-html -->
<a id="my-link" href="https://www.google.com" data-mc-cta="1" target="_blank">Click me!</a>
<!-- end snippet -->
For multiple URL using class & for-loop
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-js -->
var links = document.getElementsByClassName("link");
function redirectLink(event) {
event.preventDefault(); // Prevent the default link behavior
this.href = "https://example.com"; // Change the href to the new URL
window.location.replace(this.href); // Redirect to the new URL
}
// Loop through all links with the afflink class and add event listeners
for (var i = 0; i < links.length; i++) {
links[i].addEventListener("click", redirectLink);
links[i].addEventListener("contextmenu", redirectLink);
}
<!-- language: lang-html -->
<a href="https://www.google.com" class="link"> Google </a>
<a href="https://www.yahoo.com" class="link"> Yahoo </a>
<a href="https://www.bing.com" class="link"> Bing </a>
<!-- end snippet -->
Only Right click to all a href
with respective URL
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-js -->
var links = document.getElementsByTagName("a");
for (var i = 0; i < links.length; i++) {
links[i].addEventListener("contextmenu", function(event) {
event.preventDefault();
window.location.replace(this.href);
});
}
<!-- language: lang-html -->
<a href="https://www.Example.com"> Example </a>
<a href="https://www.wikipedia.com"> Wikipedia </a>
<a href="https://www.bing.com"> Bing </a>
<a href="https://www.stackoverflow.com"> stackoverflow </a>
<!-- end snippet -->
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论