[SalesForce] way to call javascript after action on visualforce page

I have an embedded visualforce page which calls a controller method on load.

<apex:page name="calloutPage" standardController="Case" extensions="WsCallout" action="{!getSomething}" standardStylesheets="false" >

Is there a way to call a javascript function after the controller method finishes execution, something similar to an oncomplete on a commandbutton? I am looking to reload the case page after the inline visualforce page's action call is complete.

function caseload(){
   window.top.location='/{!Case.id}'; return false;
 }

UPDATE: The idea is to do a callout to an external web service on page load and based on the values coming in, update some case fields. The case fields are getting updated as expected. However, the UI still shows the old values. If the page is refreshed a second time the UI shows the new values.

Best Answer

Note: Window.top.location wont work in lightning so you should start curbing that habit now.

Original Answer

You can simply move the fields to be internal to the VF page and display the updated data after your callout is completed. This will avoid the need for a page refresh which is both lightning compatible and avoids the infinite refresh loop discussed in the comments of this post.

Alternative Method:

Note: If you go down this path you can find a workable solution; however, for reasons discussed in the comments this is not the most straightforward or ideal solution.

Take your action out of the action attribute and move it into an action function on the page:

<apex:actionFunction name="jsName" action={!getsomething}/>

Then, put a script into the page to call it:

<script>
function reload() {
jsName();
}

reload();
</script>

Instead of using JS to redirect, use the controller. Action methods are allowed to return a pageReference that will redirect the user upon completion. Than, use login in your controller to determine if the update actually needs to be called (check the fields on your case to see if the data is correct). If it doesn't need to be called, return a null pageReference:

public pageReference getSomething () {
if (Case.field != value) {
// Do your crazy stuff
return new PageReference('/' + Case.Id);
} else {
return null;
}
}