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
Raghavendra ARaghavendra A 

Call a JavaScript function from VF page to the Home page custom component

Hi all,

How to call a JavaScript function from a Visualforce page that is embedded in the page layout as a section to the home page custom component?

The JavaScript executes when the VF page is not embedded in the pagelayout but the same will not work when we add the VF page to the page layout.

VF page --> this page is embedded in the Opportunity page layout.

<apex:page standardController="opportunity">
<script>
displayMessage();
</script>
</apex:page>

Custom Component (This code is available in the sidebar)

<script>
function displayMessage()
{
alert("hello");
}
</script>

Any help would be greatly appreciated.

Regards,
Raghu
Best Answer chosen by Raghavendra A
Scott McClungScott McClung
If I understand your question correctly, the issue is that VF pages are served from a different domain and as a result the browser will prevent this sort of cross site scripting.  The javascript in your VF page will not be allowed to call your displayMessage function.
Another approach would be to use a custom javascript button or link and embed your function call in a REQUIRESCRIPT function in that instead.  Here's a blog post that should get you started.  http://blog.scottmcclung.com/2014/01/hack-together-jquery-modal-popup-in.html