Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Well, that seems like a bad idea. Out of curiosity, does anyone know what happens if I have: `<a href="google.zip">Link</a>`?

Will the browser navigate to an external site or will it try to download google.zip?



This behavior doesn't depend on TLDs. A href will be to the local origin unless it starts with a protocol ("https://example.com") or two slashes (protocol-relative link, like "//example.com"). (The rest of the rules are that if an href starts with a single slash, then it will be a domain-relative link, otherwise it will be relative to the current URL's path.)


You need a http:// or https:// prefix to tell the browser to navitage to another site, otherwise the request defaults to being a relative path.


I see, I assume that is true for all TLDs? (Can you tell I don't do much web front-end lol)


If it's a relative path then it's not a TLD. It's only a TLD when it's part of a domain name.


Yes.


Or just //


It should try to download `google.zip` relative to your current URL.

For it to be a domain name it should at minimal be href="//google.zip", where the browser will inherit your current protocol.


It will get resolved relative to the current location.

You would need (at a minimum) '//google.zip' to trigger a cross-domain link




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: