[SalesForce] Opening a link outside salesforce

I am having a text field for entering a URL. I am using anchor tag on visualforce page to display that field.

<a target="_blank" style="text-decoration:none" href="{!contactInfo.TURL}">--Click here--</a>

When i enter value like "www.google.com" in that field and when i click on that link it renders like "https://c.cs15.visual.force.com/apex/www.google.com".

But when i enter "http://www.google.com" in that field it render correctly.

How can i make it work correctly without enforcing user to enter "http://" preceding the website link.

Best Answer

Limited Fix for Question Raised

Yes without the HTTP protocol, the browser will treat it as a relative link to the current page, to implicitly add this you can adjust the expression in your page like this.

<a target="_blank" style="text-decoration:none" href="http://{!contactInfo.TURL}">--Click here--</a>

Alternative Thoughts...

Note that you are making an assumption here on the protocol applied, e.g. http vs https, i personally think its better to clarify to users this is an actual web URL and needs to be valid or preferablly if you can, use the URL field type in the platform, this will adjust the value for the user as you desire.

enter image description here

enter image description here

enter image description here

Related Topic