1

I've been trying for the last few days to implement a lightning component on my knowledge community. The component should simply open a new tab/window to an external URL. I've tried it 100 different ways and every time it literally does nothing on click. I've tried to whitelist the URL but didn't help. Any help would be appreciated, not sure why nothing is working, I'm sure it's obvious to someone besides myself - see code below. Thanks!

Component:

<aura:component implements="forceCommunity:availableForAllPageTypes, force:appHostable" access="global">
    <button class="button" label="Open in New window" onClick="{! c.handleClick }">Contact Support</button>
</aura:component>

Controller:

({
handleClick : function(component, event, helper) {
        window.open("https://www.salesforce.com");
    },
})

1 Answer 1

1

Note that the Javascript is case sensitive,

I suggest you change from onClick to onclick.

Rewriting the code as below should work

<aura:component implements="forceCommunity:availableForAllPageTypes, force:appHostable" access="global">
   <button class="button" label="Open in New window" onclick="{! c.handleClick }">Contact Support</button>
</aura:component>
1
  • 2
    I just facepalmed so hard, it's always the small stuff isn't it - that fixed it. Thanks Mohith! I should also note for anyone who sees this, the link will not open in the community builder preview, you need to publish it before it functions.
    – JHines
    May 18, 2020 at 20:20

You must log in to answer this question.

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