HTML Strength The URL of a hyperlink that should be considered non-relative (absolute)

I have a list of URLs that our users entered for sites of different clients ... I load this list from the server into the grid so that users can see ... I made the URLs interactive by wrapping their href HTML tag .. The problem is that sometimes the user enters URLs without http: // or www. prefix, so the browser treats them as relative URLs that never happen because all of these websites are for our customers and they are all external. Is there a way to make these URLs be considered absolute rather than relative?

Here is an example:

<a target='_blank' href='google.com'>google.com</a> 

If you try this, you will see that the browser assumes that this is a relative path that should not be.

thanks


Decision:

I chose to check "//" (because I don’t know what the protocol is) maybe http or https), and if not found, I assume that this is an http site, and I prefix the URL with that - so shorter than anyone way to not force the browser to treat hyperlinks as absolute

+7
source share
3 answers

Why don't you pre-process the input and add http:// if necessary?

+3
source

You can add // in front of the URL, and this should work.

+2
source

is he relative URI.

If you want to go to http://google.com/, then you will need to set a link.

You can either temper the URIs you wrap, or try algorithmically guessing if it was intended for a relative reference or not.

Please note that you cannot safely assume that www should exist. since using this for websites is just an agreement and no longer follows it.

0
source

All Articles