简体   繁体   中英

How do I create a link without the URL being visible in Javascript?

As part of printing the console.log for a Javascript project, I need to print a URL without showing it to the user. It should work like this: Click Here

Upon clicking the 'Click Here' text, I should be able to redirect the user to the given link, and the user should not get to see the link.

Request someone to help with this.

您如何看待这个解决方案?

<a onClick="window.location.href='https://google.com';"/>

You will need a href attribute to your anchor tag. This href will be shown to the user in the bottom left. But you could do something like this:

<a href="javascript:void(0)" onclick="location.href='http:\\www.google.com'">Link</a>

The javascript in the href will do literally nothing. And the javascript in the onclick function will redirect to the link.

Unfortunately the user sees something like this in the bottom left:

左下角显示的锚href

May be little indirect way like this.

<a href="javascript:var w=window,a2b=w.atob;w.location=a2b(a2b('YUhSMGNITTZMeTluYjI5bmJHVXVZMjl0'))"> Click Here </a>

Its actually very simple. Just using base64 encoded value twice (or some other encryption logic).

But note any client side code is never secure.

Example: If you use encryption, there is no way you can call decryption without storing the key in client variable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM