function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
IvarIvar 

Referencing elements in Visualforce

Hi everybody.

 

I have been messing around with trying something and am not sure where I am doing this wrong, and was hoping someone might be able to point me in the right direction.

 

My very short visualforce code is included below. What I am trying to do is to create a visualforce page that contains an iframe that points to a salesforce dashboard. The page then also contains a small javascript segment that I want to eventually use to periodically refresh the dashboard presumably by firing off the click event on the dashboard's refresh button. I haven't created the periodical timeout loop, as I can't even reference the button.

 

My problem is that I am not able to reference the refresh button. I have tried many variations but I never seem to be able to find that button. Please if someone has an idea I would really appreciate a hint :)

 

Maybe I am using the wrong technology to reference the object, maybe I got the id wrong, at any rate, any help will be greatly appreciated :)

 

 

<apex:page sidebar="false" showHeader="false">
<div id="test">myText</div>
  
  <iframe id="box" src="https://emea.salesforce.com/01Z200000000kFc" width="100%" height="1000" />
 <script language="javascript">
     
     document.getElementById("box").document.getElementById("{!$Component.refreshButton}").click();
     
     
  </script>
</apex:page>

 

 

bob_buzzardbob_buzzard

I think you are hitting the browser's cross site scripting security.  This effectively stops javascript accessing pages/windows/frames from other domains.  As your visualforce page is served from a different domain to ema.salesforce.com, you can't access the details.

IvarIvar

Hmm... that is a good point bob_buzzard. Any ideas how I can do this without running into that?

bob_buzzardbob_buzzard

I've been playing around with javascript in a sidebar component that clicks various things.  The problem is that the sidebar doesn't get displayed for dashboards :(

IvarIvar

Hmm... makes me wonder. Now we can add visualforce components directly to dashboards. Would you think cross-site scripting restrictions would still apply if I made a visualforce page specifically to click the button and added that as a component to a dashboard?

bob_buzzardbob_buzzard

I think it would, as it would still come from the visualforce server rather than emea.salesforce.com, as the rest of the dashboard.   

Pradeep_NavatarPradeep_Navatar

In my opinion, there is a syntax problem in the javascript code :

 

document.getElementById("box").document.getElementById("{!$Component.refreshButton}").click();

 

It seems that you have used 'document' twice in your code.

 

Try using the below mentioned code :

 

window.parent.parent.document.getElementById("{!$Component.refreshButton}").click();

 

Hope this helps.