0

What I'm trying to do requires me to have a home page component that can change an element on another home page component but each component seems to be unique to itself. Does any one know how to accomplish this

Here is an example A simple home page component with a div element call 'myTest'

<apex:page >
<h1>Congratulations</h1>
This is your new Page
<div id="myTest">I want to change this text</div>
</apex:page>

This is a second home page component but I cannot get it to talk to the other component and see it's div element. It does see it's own element 'myjavamessages' but does not see anything on the other component. Can someone hopefully tell me how?

    <apex:page >
    <div id="myjavamessages">My Custom Home Page Object - to add javascript to home pages</div>
    <div id="demoContainer">
    <script language="JavaScript">
      try{
        var pa=document.getElementById("demoContainer").parentNode.parentNode;
      //  pa.style.display = "none";
      } catch(err){
        alert('There was an error on this webpage='+err.description);
      }
    </script>
    <script language="JavaScript">
      function CustomApproval(){
        try {
          var hrefList = document.getElementsByTagName("div");
          var peName = document.getElementById("myjavamessages").parentElement.parentElement.nodeName;
          // This works and talks to 'myjavamessages' element        
          document.getElementById('myjavamessages').innerHTML = 'Divs Found ' + hrefList.length + '<br />' + peName;
          // this fails as it does not seem to able to get out of it's page context to see the whole document
          document.getElementById('myTest').innerHTML = 'I've changed the text in another element';
        } catch(err) { alert(err); }
      }

       CustomApproval();     
    </script>
    </div>
    </apex:page>
  • Is it necessary that each component is truly it's own component? It sounds like they are dependent on one another, so why not just put them both in the same component? Then you would be able to access the elements you want to access. – Kyle Jun 30 '16 at 18:45
  • Because I'm trying to change the links associated with approvals on that are on the homepage so we can redirect them to our own visual force approval process page. This was just a test to see if I could read and change elements in another section of the home page – Ohmicron Jun 30 '16 at 18:46

Your Answer

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

Browse other questions tagged or ask your own question.