salesforce zero-based learning (ninety-four) vf page content classic pop under pagelayout introduced to update this page layout

We in the classic environment, sometimes for a local page layout can not be achieved, can be introduced into a vf page to enhance the standard page layout function, sometimes the requirements of this vf page of some changes need to update this page layout or the current that vf page pops up a new the window changes need to refresh the whole page layout, the project met this demand, because the front is not good, took some time to solve him, mark it late have met the same scene, can take over directly used.

Let the demo pop up a new window based on the current introduction of vf page, the window of the variable part of the current page layout will be automatically reassigned need to refresh this page layout to achieve the desired effect.

 GoodsDemoPage.page: for displaying a button, click on this button pops up a sub-page

 1 <apex:page standardController="Goods__c">
 2     <script type="text/javascript">
 3         function openChangeStatusWindow() {
 4             var directURL = '/apex/GoodsDemoDirectPage?id={!Goods__c.Id}';
 5             window.open(directURL,'newwindow','height=100,width=200,top=200, left=350,toolbar=no, menubar=no, scrollbars=no, resizable=yes, location=no, status=no');
 6         }
 7 
 8         function refreshPagelayout() {
 9             window.top.location.href = '/{!Goods__c.Id}';
10         }
11     </script>
12     <apex:form>
13         <input type="button" value="清空Status状态" onclick="openChangeStatusWindow();" />
14     </apex:form>
15 </apex:page>

GoodsDemoDirectPage.page: Goods for emptying the state of the Status update the parent level and page layout.

 1 <apex:page  showHeader="false">
 2     <script src="../../soap/ajax/42.0/connection.js" type="text/javascript"></script>
 3     <script type="text/javascript">
 4         sforce.connection.sessionId='{!GETSESSIONID()}';
 5         function changeGoodsStatus() {
 6             var goods = new sforce.SObject("Goods__c");
 7             goods.Id = '{!$CurrentPage.parameters.Id}';
 8             goods.Status__c = null;
 9             result = sforce.connection.update([goods]);
10             console.log('result' + result);
11             if(result[0].getBoolean('success')) {
12                 window.opener.refreshPagelayout();
13                 window.close();
14             } else {
15                 alert('error occured');
16             }
17         }
18     </script>
19     <apex:form>
20         <input type="button" value="清空" onclick="changeGoodsStatus();" />
21     </apex:form>
22 </apex:page>

The GoodsDemoPage configuration page layout can Goods__c of this sObject. Click "Clear Status status' button later, will pop up a page, click on the page in the 'Clear' button after the pop-up page will be closed and the current page layout will be automatically refreshed.

There are two key points here: window.top and window.opener. These two differences are as follows:

window.top return for top-level window, that is, the browser window. GoodsDemoPage embedded in the page layout, then against GoodsDemoPage, its window.top point is the current page layout corresponding window.

window.opener return to open the page for this page. For GoodsDemoDirectPage, open the GoodsDemoPage, so for GoodsDemoDirectPage, its window.opener points to GoodsDemoPage. So for this demo, we only need to call refreshPageLayout method GoodsDemoPage by window.opener, then use window.top pointing to the current URL to refresh the process.

Summary: The article mainly related to js knowledge, because I js more vegetables, if there is an error or a better way to welcome that, do not understand the welcome message.

Guess you like

Origin www.cnblogs.com/zero-zyq/p/11255327.html