How to turn a domain into exile, not knowing the Protocol?

Have a domain name, type which needs to be turned into a valid link in HTML template, not knowing the true Protocol (HTTP(S)).
The website can be HTTP-only or HTTPS-only, and need to accurately access the correct.

Links without Protocol resolvase as a local, and with just a double slash (// will resolvida on the Protocol that is used on the page.

Browsers (eg. Chrome) as it can be resolved need an address for the domain, but how to do it in simple HTML?
Allowed to use JS.
March 23rd 20 at 19:12
2 answers
March 23rd 20 at 19:14
In fact, it is a problem of specific sites - they should always be available via HTTP, though with an unconditional redirect to HTTPS. Accordingly, it is sufficient to simply specify the Protocol http://.
But if you really want to bother, it is possible for the client in the background to make a request to the site address with https:// and if you come the response is 2XX or 3XX, to substitute this Protocol.
Another way to see if the website of a particular Protocol but to make there request does not exist.
March 23rd 20 at 19:16
In normal situation the link will work out a redirect to https.
Ie you can give links in http.
If the site is https-only, can not redirects, etc. - it is purely their problem, let them decide.
As a techie, I completely agree with you, but business, unfortunately, is not satisfied with the position, "it's the customer's problem". - Andrew commented on March 23rd 20 at 19:19
@Andrew, in this case, I suggest to use the solution @Gregoria.Kreiger. But there are tons of aspects, but what if you want to process on the client 100500+ links? What if over http returns 200 OK but the content different? - alf_Moore commented on March 23rd 20 at 19:22

Find more questions by tags Web DevelopmentHTMLJavaScript