2

I have an API which i need to open to activate, but I don't want that users actually see the link. Does JQuery or Javascript provide a way to solve this? I just use windows.open(...) to open the link.

Ynias Reynders
  • 309
  • 1
  • 14
  • 3
    You can make an ajax call to the link. – Gaurav Ojha Apr 26 '17 at 09:16
  • 1
    Simply call it when page got load. like, – Unknown_Coder Apr 26 '17 at 09:17
  • May be this could help - http://stackoverflow.com/questions/503093/how-to-redirect-to-another-webpage-in-javascript-jquery – Pugazh Apr 26 '17 at 09:19
  • check my answer and tell me if it is useful to you or not – Unknown_Coder Apr 26 '17 at 09:20
  • 1
    Please note that you can never truly hide the URL from a user who knows his way around the dev console. Via the console, any user is able to track all network calls that your webpage makes, including external sources. You can hide a URL from plain sight, but you cannot securely hide it from a user who knows where to look. – Flater Apr 26 '17 at 09:22
  • Thank you guys for the big response, I just used an Ajax call and it works. I generated the hyperlink myself so it could answer to python flask so a lot of the solution in html itself would be a bit to complicated for something as simple as this. Again ty @GauravOjha – Ynias Reynders Apr 26 '17 at 09:26

2 Answers2

0

As long as the link is between <a></a> tags, the href will always be displayed on hover for browsers. However, you can do it with events like onClick="function(){}", which can be applied on any kinds of elements, like div.

Catalin Iancu
  • 722
  • 5
  • 18
0

If you want to hide the href but still want it to redirect when clicked, use this.

Get the URL and put it in data attribute. Then remove the href attribute.

$('a').each(function() {
    $(this).data('href', $(this).attr('href')).removeAttr('href');
});

When clicked on anchor, get the URL from data attribute and redirect.

$('a').on('click', function() {
    window.location.href = $(this).data('href');
});
NewUser
  • 12,713
  • 39
  • 142
  • 236
  • 1
    You might want to be more specific than using just `$("a")`. If multiple links exist on the page, one will overwrite the other's value and you'll always end up with the href data from the _last_ processed link. – Flater Apr 26 '17 at 09:24