Showing posts with label Embedded VF. Show all posts
Showing posts with label Embedded VF. Show all posts

Wednesday, January 4, 2017

Refresh Standard Page Window from Embedded Visualforce page in Salesforce

I learnt this easy way of refreshing a parent page when an action is performed in the iFrame. Let's say you have a button in your iframe page which performs some function(Save in our case here).

<div>
<apex:commandButton value="Save" action="{save}" onComplete="refreshWindow();" />
</div>

You can put a script tag at the bottom of the iFrame page to code refreshWindow method as below:

<script>
       refreshWindow = function(){
            console.log('Refreshing window now...');
            window.top.location='/{!recordId}';
            return false;
       }
</script>


top.location (which is an alias of window.top.location) returns the location of the topmost window in the window hierarchy. If a window has no parent, top is a reference to itself (in other words, window === window.top)