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:


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


    iframeOnLoad: function(){
           customCss = document.getElementById('customCSS').innerHTML;

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.

  • Am I missing something cause I do not see an element with the id of customCSS in your example – Eric Feb 17 '17 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 Feb 17 '17 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 Feb 17 '17 at 20:19
  • @sfdcfox Ya I just found out about the LockerService Security feature. Now I know why. – OpuLance Feb 17 '17 at 21:01

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.