javascript 在 href 属性中隐藏 HTML 链接

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14170728/
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-10-26 20:54:28  来源:igfitidea点击:

Hiding HTML link in href attribute

javascripthtmlonclick

提问by Ribice

OK, I'm not that good with HTML but I'll try to express myself as good as possible.

好吧,我不太擅长 HTML,但我会尽量表达自己。

Lets say I have a link for a game in href attribute. By using JS on.click, as soon as user clicks on the link, he gets a pop-up window that forces him to subscribe. After they subcribe, the link is automatically opened and download starts.

假设我在 href 属性中有一个游戏链接。通过使用 JS on.click,只要用户点击链接,他就会得到一个弹出窗口,迫使他订阅。他们订阅后,链接会自动打开并开始下载。

But the problem is that the link is visible, so he can simply right click it, copy link location, paste it and ... well you got the idea. Also while hovering the link, its shown in the bottom (depending on your browser).

但问题是链接是可见的,所以他可以简单地右键单击它,复制链接位置,粘贴它......好吧,你明白了。同样在悬停链接时,它会显示在底部(取决于您的浏览器)。

How to hide that link from user (still need to use on mouse click)?

如何向用户隐藏该链接(仍然需要在鼠标单击时使用)?

He doesn't need to see it, it opens as soon as he subscribes.

他不需要看,订阅后就打开了。

Thankful

感恩

回答by ryanc1256

It is better if you give href='#'and use the same JS function to redirect the user to the link.

如果您提供href='#'并使用相同的 JS 函数将用户重定向到链接,则更好。

To use some of the text from the other Answerer..

使用其他回答者的一些文字..

<a href="#" onClick="window.location = 'my-website.com/download/super-game.zip';"> Download link </a>

This Will Open the link but I would do it something like this...

这将打开链接,但我会这样做......

  <a href="#" onClick="download('my-website.com/download/super-game.zip')"> Download link </a>

and then in a JavaScript file

然后在一个 JavaScript 文件中

function download(link)
{
 window.location = link;
 return false;
}

This is how I would do it but its very silly... By silly I mean stupid, why do you want a user be able to click on the but not see the link? there is only one way to do it, its to use a server side language, and therefore the user won't be able to see the link...

这就是我要做的,但它非常愚蠢...愚蠢我的意思是愚蠢,为什么您希望用户能够点击但看不到链接?只有一种方法可以做到,它使用服务器端语言,因此用户将无法看到链接......

回答by Sumit Malik

It is better if you give href='#' and use the same JS function to redirect the user to the link.

最好给 href='#' 并使用相同的 JS 函数将用户重定向到链接。

回答by ostrichegret

GIT : https://github.com/michaelhartomo/js-ninja-href

GIT:https: //github.com/michaelhartomo/js-ninja-href

js-ninja-href

js-忍者-href

Javascript native library to hide / cloak your real url link.

用于隐藏/隐藏您的真实 url 链接的 Javascript 本机库。

Really useful to hide your referral link.

隐藏您的推荐链接非常有用。

Get all your lost revenue, because some people don't want to use your referral link.

获得所有损失的收入,因为有些人不想使用您的推荐链接。

It will innocently show a clean url, but when the user click ( left , middle, right ) it will redirect them to somewhere else.

它会无辜地显示一个干净的 url,但是当用户点击(左、中、右)时,它会将它们重定向到其他地方。

Install Download and extract the .zip file: https://github.com/michaelhartomo/js-ninja-href/archive/master.zip

安装 下载并解压 .zip 文件:https: //github.com/michaelhartomo/js-ninja-href/archive/master.zip

Setup Include the script: ninja-href.min.js

设置包含脚本:ninja-href.min.js

<script src="js/ninja-href.min.js"></script>

Now run the ninja-href function ( by default, it will listen to ninja-href class )

现在运行 ninja-href 函数(默认情况下,它会监听 ninja-href 类)

ninja_href(".ninja-href");

Set the link you want to hide / cloak just like this ( open in new window ):

像这样设置要隐藏/隐藏的链接(在新窗口中打开):

<a href="http://google.com/" class="ninja-href" data-ninja-url="http://frozenfire.us/" data-ninja-target="_blank"> Go to Google </a>

You can also open the link in current window :

您也可以在当前窗口中打开链接:

<a href="https://tomplayer.top/" class="ninja-href" data-ninja-url="https://m.do.co/c/9072c848dc6e" data-ninja-target="_self"> TOP Charts 100 WORLD & 50 K-POP! </a>

Very useful to cloak referral link just like this :

像这样隐藏推荐链接非常有用:

<a href="https://google.com/free/RlJPWkVORklSRS1UT01QTEFZRVIuQVBQLU1JQ0hBRUxIQVJUT01PLkNPTQ==" class="ninja-href" data-ninja-url="https://m.do.co/c/9072c848dc6e" data-ninja-target="_self"> GET FREE 10 USD FOR SSD VPS HOSTING! ( You can use it for 2 months ) </a>

jsFiddle Example : https://jsfiddle.net/t5f7n7gL/1/

jsFiddle 示例:https://jsfiddle.net/t5f7n7gL/1/