0

Weird one but is it possible to make <a href="http://www.helloworld.com">Link</a> work without the text helloworld.com being in the source?

Long story but I have function breaking helloworld because it matches it and I remember back to my AOL days where you could "encode" a url to look completely different text but it still took you to that url? Note I dont mean encoding the ? or = etc - but the actual text of domain name... have I completely imagined this?

j08691
  • 204,283
  • 31
  • 260
  • 272
CerIs
  • 527
  • 3
  • 6
  • 14
  • What is the problem preventing the link from working? It sounds like you should fix that rather than looking for a hacky alternative. – Alex K. Aug 07 '15 at 15:08
  • I believe it accomplished (AOL) The same way Bitly links do... A central server with essentially a lookup or redirect...? – Austin T French Aug 07 '15 at 15:10
  • I agree with fixing function thats breaking it but javascript doesnt have negative look-behind which is the wall ive hit with that :( – CerIs Aug 07 '15 at 15:11
  • Things that spring to mind and _don't_ work: percent-encoding is only applied to the path, not the domain, and punycode does pass through pure ascii names unchanged. (Actually, various converters are in two minds if `www.xn--helloworld-.com` is valid, and it still contains the substring, whcih might not solve your problem.) – Ulrich Schwarz Aug 07 '15 at 15:13
  • You can always work around the lack of NLB in other ways, depending on what you want to do. – Alex K. Aug 07 '15 at 15:16

2 Answers2

0

Weird one but is it possible to make <a href="http://www.helloworld.com">Link</a> work without the text helloworld.com being in the source?

To what end? If you want to totally prevent users from figuring out the URL before they click the link, no that's impossible. If instead you just want to prevent that URL from being picked up by scrapers that don't run JavaScript, then yes that is entirely possible.

What I would do in that case is add a data attribute to the link with an encoded version of the URL.

<a href="#" data-href-rot13="uggc://jjj.uryybjbeyq.pbz">Link</a>

Then in your JavaScript, decode. Untested jQuery example to get you started:

$('a[data-href-rot13]').each(function (index, el) {
  $(this).attr('href', rot13($(this).attr('data-href-rot13')));
});

Of course, you might want a different algorithm than rot13. You could use AES and base-64 encode the output for use in the tag. In case you do want rot13, see this post: https://stackoverflow.com/a/15747894/362536

Community
  • 1
  • 1
Brad
  • 159,648
  • 54
  • 349
  • 530
  • cool thanks, i can actually do this before final version gets to client so is not about stopping user from getting link. So I could encrypt the URL before my function then decrypt back to normal after with above... thanks for point in right direction :) – CerIs Aug 07 '15 at 15:20
0

You can url encode your URL:

(here just on the 'l' character)
<a href="http://www.he%6C%6Cowor%6Cd.com">Hello World !</a>

It's not an encryption, but a simple encoding. Url cannot use all characters inside of them, so special chars can be passed with the form %XX where XX is the hexadecimal representation of the char.

You browser will decode it, before using it. This coding is normally seen after the url for params and path (ie: url.com/this%20space), but it is also available inside the domain name.

You can encode an url like that with this short javascript:

var encodeUrl = function(url) {
        return url.split('//')[0] + '//'
             + url.split('//')[1]
                  .replace(/[a-z ]/gi, function(c) {
                      return '%' + c.charCodeAt(0).toString(16);
                  });
    }

url = 'http://www.helloworld.com/';
encodedUrl = encodeUrl(url)
document.body.innerHTML = 'Raw url: <pre>' + url + '</pre>EncodedUrl: <pre>' + encodedUrl + '</pre>Result: <a href="' + encodedUrl + '">TEST</a>';
Cyrbil
  • 6,341
  • 1
  • 24
  • 40