2

Somewhat new to Salesforce. I have a lightning component that has an iframe in it. The component will be in the lightning communities. There is a method in the controller that gets called once the iframe is loaded. For some reason I can't access any DOM elements, it's always null. Here's an example snippet:

Component

<aura:component implements="forceCommunity:availableForAllPageTypes">
     <iframe src="/mypage" onload="{!c.iframeOnLoad}" class="myIframe" frameBorder="0"/>
</aura:component>

Controller

({       
    iframeOnLoad: function(){
        try{
           customCss = document.getElementById('customCSS').innerHTML;
        }
        catch(ex){
           console.log(ex);
        }
    }
})

The customCss element is actually there but for some reason it's not getting it. If I put that js snippet in the browser console, it does get the innerHTML in that element. I hope that understands it.

4
  • Am I missing something cause I do not see an element with the id of customCSS in your example
    – Eric
    Commented Feb 17, 2017 at 15:12
  • It's outside of the component. It's the ID of the custom css that I set in the branding section of lightning communities.
    – OpuLance
    Commented Feb 17, 2017 at 15:13
  • @OpuLance You can't interact outside of your DOM as a matter of security. You must interact with your other elements using application events.
    – sfdcfox
    Commented Feb 17, 2017 at 20:19
  • @sfdcfox Ya I just found out about the LockerService Security feature. Now I know why.
    – OpuLance
    Commented Feb 17, 2017 at 21:01

1 Answer 1

1

DOM manipulation, due to this critical update "Enable Lightning LockerService Security", will be not more usable. Instead, you can use component.set and component.get lightning pure methods.

You must log in to answer this question.

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