[SalesForce] Open an Link from a LWC in a new Tab

I have a custom LWC that has a link on it for a customers website. It should open a new tab in the web browser with the companies website. It currently opens a new link with a salesforce url prefix.

Example:

Website Value: google.com

On Click: lightning.force.com/lightning/r/Lead/00Q5500000Bf9T9EAJ/google.com

Code Snippet:

                           <dt class="slds-dl_horizontal__label slds-text-title">Website:</dt>
                            <dd class="slds-dl_horizontal__detail">
                                <p if:true={accountWebsite}>
                                    <a href={accountWebsite} target="_blank">Company Website</a>
                                </p>
                            </dd>
    get accountWebsite(){
        return getFieldValue(this.account.data, 'Account.Website');
    }

The odd thing is that I am 99.99% sure that this was working a few months ago. I know that there have been a couple of API version and changes to LWC, so I am not sure if that might be a cause.

Anyone insight would be greatly appreciated.

Thanks,

Best Answer

Due to your website format (google.com), it'll function as a relative URL which makes it root-relative and uses the domain of the page as the prefix (as you noted).

You need to add a forward slash to your field as in one of the following prefixes to make it an absolute URL.

  1. http://www.google.com
  2. https://google.com

This is highlighted in the lightning-formattedURL doc describing relative vs. absolute URLs

enter image description here