We have a user submitted string that the user wants to be treated as a hyperlink when displayed on our site.
The users string will be displayed on the page like this:
<a href="userstring">userstring</a>
the issue this causes is that if the user enters www.stackoverflow.com they won't be redirected
Instead it would go to http://mywebsite.com/www.stackoverflow.com
So I'm looking for a way of a link being treated as absolute rather than relative via the html link tag?
otherwise I'm happy for any other suggestions. Maybe using javascript to open the link rather than html?
local file system and intranet links are the main issues at the moment with checking the string for http, www., https
we're currently using javascript and jquery, asp.net server side
Thanks in advance
You need to specify link protocol, host and optionally, port. Otherwise link will be considered as relative (to current context, ie to current protocol, host and port).
Check location API to see how you need to modifiy user's value before putting it into href attribute.
When user submits a link, check whether it includes http://, www, .com etc. If it does not include, add it. Not only it will serve as a validation, it will make your links absolute.
As for ability to point to your own website (internal links) you can put extra radio buttons for internal or external links.
You can read about absolute and relative URLs here .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.