0

I have a Lightning Data table in my LWC. It is populated with line item data from an external source through apex. I want the data table to open in a new tab when a button is clicked.

Currently it is opening a new tab with the salesforce url and gives a message "This page is not available in Lighting...". The line items are not records but just text.

I have tried the following. I don't need a specific url as its just a tab to show the data table which is populated by apex callout:

<lightning-button label="google" title="Non-primary action" onclick={handleClick} class="slds-align_absolute-center"></lightning-button>

handleClick() {
    var url = "www.google.com";
    window.open(url, "_blank");
}

I have also tried with _blank and _parent:

<a href="www.google.com" target="_blank">Go to Site</a>
0

1 Answer 1

2

In a browser, if you do not make it an absolute URL, it is presumed to be a relative URL. You can use either:

//www.google.com/

Or:

https://www.google.com/

The former tells the browser that this is a TLD (top level domain), using the current protocol (https), while the latter also explicitly specifies that https should be used.

Also, if you need a blank tab, just ask for it:

about:blank
2
  • Thanks. Any ideas why with the button about:blank does not load but with the <a> tag it does
    – M guy
    Commented Sep 2, 2020 at 14:16
  • @Mguy buttons are typically used to submit a form. They don't do navigation on their own. You could use an onclick, though, which should work.
    – sfdcfox
    Commented Sep 2, 2020 at 14:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .