Because of the service cloud console context it is a best practice to open external pages in the console too, for example in a new sub tab. So you will get no problem concerning cross domain error and hold all important data on the same page, that is, in a console. From the visualforce page you can then control the refresh/close process using a service cloud console integration Toolkit (after saving function close the current tab and refresh an opener case tab).
The first step is to open a visualforce page (your current popup) in a sub tab. For that you need to modify your custom button on the Case object that will do this job.
Step 1: Custom button on the Case - Execute Javascript
Put the following javascript code on the custom button:
// Connecting to the Toolkit
{!REQUIRESCRIPT("/support/console/30.0/integration.js")}
// While opening a new tab witha visualforce page we need to provide
// a full page URL like https://c.na9.visual.force.com/apex/YourPagename
var sfdcUrlName = window.location.protocol + '//' + window.location.host;
// In this variable we will save a parent tab ID
// It is needed for the subTab opener function.
// A new sub tab will be opened within this parent tab.
var myParentTabId = '';
// Here evaluating a parent tab ID
var readParentId = function(result){
myParentTabId = result.id;
};
sforce.console.getEnclosingPrimaryTabId(readParentId);
// Now open our visualforce page in a new subtab
// We pass a subtab ID as a URL parameter that could be read
// on the visualforce page
var openSubtab = function(result){
sforce.console.openSubtab(myParentTabId, sfdcUrlName + '/apex/YourVisualforcePageName?tid=' + result.id, true, 'My popup title', null);
};
sforce.console.getEnclosingTabId(openSubtab);
Step 2: Visualforce Page
Now we will create a simple visualforce page:
<apex:page showHeader="false" sidebar="false">
<!-- Service cloud console integration toolkit script -->
<apex:includeScript value="/support/console/30.0/integration.js"/>
<script type="text/javascript">
// This function will close the current tab with this page
// and after that refresh the opener case tab
function closeCurrentTab() {
sforce.console.getEnclosingTabId(closeThisTabAndRefreshParent);
}
var closeThisTabAndRefreshParent = function closeThisTabAndRefreshParent(result) {
// Refreshing a subtab by ID.
// An opener tab id was passed as a URL param.
sforce.console.refreshSubtabById('{!$CurrentPage.parameters.tid}', true);
// Closing current tab
sforce.console.closeTab(result.id);
};
</script>
<apex:form>
Some form elements are here...
<!-- This button executes some apex funxtion -->
that is not presented in my code and then
executes a javascript function that will close
current tab and refresh an opener tab -->
<apex:commandButton value="Save and close"
oncomplete="closeCurrentTab(); return false;"/>
</apex:form>
</apex:page>