在鼠标光标放置在ahref标签上时,隐藏或操纵浏览器左下角的URL。

huangapple go评论57阅读模式
英文:

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:

屏幕截图:

在鼠标光标放置在ahref标签上时,隐藏或操纵浏览器左下角的URL。

英文:

I want to hide, remove or manipulate URL display in left-bottom in browser like Google.

Trying with JS:

&lt;a href=&quot;https://example.com&quot; onmouseover=&quot;window.status=&#39;google.com&#39;; return true;&quot; onmouseout=&quot;window.status=&#39;&#39;; return true;&quot;&gt;Example&lt;/a&gt;

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 -->

&lt;a href=&quot;http://example.com&quot; class=&quot;no-tooltip&quot;&gt;Link&lt;/a&gt;

<!-- end snippet -->

Google example :

在鼠标光标放置在ahref标签上时,隐藏或操纵浏览器左下角的URL。

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&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=&amp;cad=rja&amp;uact=8&amp;ved=2ahUKEwizyLqk54X-AhWIUGwGHeqDA5EQFnoECCUQAQ&amp;url=https%3A%2F%2Fexample.com%2F&amp;usg=AOvVaw2g9Si57HiLP2X7LeNGKaHd

Screenshot :

在鼠标光标放置在ahref标签上时,隐藏或操纵浏览器左下角的URL。

答案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 (){
   $(&quot;a&quot;).click(function(event) {
       event.preventDefault(); //stop the redirect
       location.href=&quot;https://www.wikipedia.org&quot;; 
   });
});

<!-- language: lang-html -->

&lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js&quot;&gt;&lt;/script&gt;

&lt;div class=&quot;link&quot;&gt;
    &lt;a href=&quot;http://www.google.it&quot;&gt;Google&lt;/a&gt;
&lt;/div&gt;

<!-- end snippet -->

Hope i was helpful!

答案2

得分: 1

你不能改变 Window.status。要实现所需的结果,你可以使用 location.hreflocation.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(&quot;my-link&quot;);
  link.addEventListener(&quot;click&quot;, function(event) {
    event.preventDefault(); // Prevent the default link behavior
    
    // Change the href to the new URL
    link.href = &quot;https://www.example.com&quot;;
    
    // Redirect to the new URL
    //window.location.href = link.href;
    window.location.replace(link.href);
  });

<!-- language: lang-html -->

&lt;a id=&quot;my-link&quot; href=&quot;https://www.google.com&quot; data-mc-cta=&quot;1&quot; target=&quot;_blank&quot;&gt;Click me!&lt;/a&gt;

<!-- 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(&quot;my-link&quot;);

function redirectLink(event) {
  event.preventDefault(); // Prevent the default link behavior
  link.href = &quot;https://www.example.com&quot;; // 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(&quot;click&quot;, redirectLink);
link.addEventListener(&quot;contextmenu&quot;, redirectLink);

<!-- language: lang-html -->

&lt;a id=&quot;my-link&quot; href=&quot;https://www.google.com&quot; data-mc-cta=&quot;1&quot; target=&quot;_blank&quot;&gt;Click me!&lt;/a&gt;

<!-- 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(&quot;link&quot;);

function redirectLink(event) {
  event.preventDefault(); // Prevent the default link behavior
  this.href = &quot;https://example.com&quot;; // 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 &lt; links.length; i++) {
  links[i].addEventListener(&quot;click&quot;, redirectLink);
  links[i].addEventListener(&quot;contextmenu&quot;, redirectLink);
}

<!-- language: lang-html -->

&lt;a href=&quot;https://www.google.com&quot; class=&quot;link&quot;&gt; Google &lt;/a&gt;
&lt;a href=&quot;https://www.yahoo.com&quot; class=&quot;link&quot;&gt; Yahoo &lt;/a&gt;
&lt;a href=&quot;https://www.bing.com&quot; class=&quot;link&quot;&gt; Bing &lt;/a&gt;

<!-- 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(&quot;a&quot;);
 for (var i = 0; i &lt; links.length; i++) {
   links[i].addEventListener(&quot;contextmenu&quot;, function(event) {
     event.preventDefault();
     window.location.replace(this.href);
   });
 }

<!-- language: lang-html -->

&lt;a href=&quot;https://www.Example.com&quot;&gt; Example &lt;/a&gt;
&lt;a href=&quot;https://www.wikipedia.com&quot;&gt; Wikipedia &lt;/a&gt;
&lt;a href=&quot;https://www.bing.com&quot;&gt; Bing &lt;/a&gt;
&lt;a href=&quot;https://www.stackoverflow.com&quot;&gt; stackoverflow &lt;/a&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年3月31日 16:07:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/75896209.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定