Href without http(s) prefix
It's possible, and indeed you're doing it right now. It just doesn't do what you think it does.
Consider what the browser does when you link to this:
href="index.html"
What then would it do when you link to this?:
href="index.com"
Or this?:
href="www.html"
Or?:
href="www.index.com.html"
The browser doesn't know what you meant, it only knows what you told it. Without the prefix, it's going to follow the standard for the current HTTP address. The prefix is what tells it that it needs to start at a new root address entirely.
Note that you don't need the http:
part, you can do this:
href="//www.google.com"
The browser will use whatever the current protocol is (http
, https
, etc.) but the //
tells it that this is a new root address.
html - links without http protocol
The inclusion of the “http:” or “https:” part is partly just a matter of tradition, partly a matter of actually specifying the protocol. If it is defaulted, the protocol of the current page is used; e.g., //www.example.com becomes http://www.example.com or https://www.example.com depending on the URL of the referring page. If a web page is saved on a local disk and then opened from there, it has no protocol (just the file: pseudo-protocol), so URLs like //www.example.com won’t work; so here’s one reason for including the “http:” or “https:” part.
Omitting also the “//” part is a completely different issue altogether, turning the URL to a relative URL that will be interpreted as relative to the current base URL.
The reason why www.example.com works when typed or pasted on a browser’s address line is that relative URLs would not make sense there (there is no base URL to relate to), so browser vendors decided to imply the “http://” prefix there.
how can i open a link without using http info..?
You should force the user to insert a valid url, for instance by using a proper inpout
tag:
<input type="url" placeholder="Enter a valid URL - e.g. http://path.to/website">
In case you can't/you don't want to edit existing content
$('a[target="_blank"]').click(function(e){
e.preventDefault();
window.location = /^(http|https):/.test(this.href) ? this.href : 'http://' + this.href;
});
URL without http|https
Protocol relative URL
You may receive unusual security warnings in some browsers.
See also, Wikipedia Protocol-relative URLs for a brief definition.
At one time, it was recommended; but going forward, it should be avoided.
See also the Stack Overflow question Why use protocol-relative URLs at all?.
HTML force URL hyperlink to be treated as non-relative (absolute)
Why don't you preprocess the input and append http://
when necessary?
Symfony create links without http:// prefix
Why don't you create a custom validator, that automatically converts the user submitted address to a valid URI. (Always add the http(s)://
part).
That way everything is stored the same way in your database (it all has exactly the same meaning), and no matter where you want to display an URL, you'll be sure it's valid.
Of course you could also override the $companies->getUrl() function to test if the URL is absolute, and if not add the protocol part. But then the data in your database still isn't stored 'the same way'.
Why does href=example.com not open example.com in new tab? Instead it opens a new tab but appends example.com to the end of the current URL
The third one is a link to the page named example.com
on the current server.
Just because it has a .com
extension does not mean it is magically a domain name. It's like that by design and by definition.
The first piece of text (until the first /
after it, if any) is treated as a domain name if and only if there is //
or protocol://
at the beginning. And the text is treated as a (sub)page if there isn't.
Related Topics
Emulate Ie7 for Ie8 But Not for Ie9 Using "X-Ua-Compatible"
Put Search Icon Near Textbox Using Bootstrap
Django Doesn't Display Newline Character When Rendering Text from Database
Stop Lastpass Filling Out a Form
Inline Svg Vs Svg File Performance
Is There a Vr (Vertical Rule) in HTML
Twitter Bootstrap: Column Re-Ordering for Full Width Divs
Can HTML5 Websockets Connect 2 Clients (Browsers) Directly Without Using a Server? (P2P)
Drop Down Menu/Text Field in One
HTML5 Autoplay Video in Mobile Device
How to Remove Only Underline from A:Before
Display Text on Mouseover for Image in HTML
Gradient Colors in Internet Explorer
Difference Between Classes and Ids in CSS? Explain with Example of Where to Use