Window.close无法在页面参考Apex方法中工作

问题描述 投票:0回答:1

我在apex控制器中有页面引用方法。我需要关闭当前标签。

这是我的代码:

public PageReference savePostSurveyAnswer(){
        String sitePathPrefix = Site.getPathPrefix();
        System.debug('savePostSurveyAnswer method start');

        CaseIdentifierIdValue = ApexPages.currentPage().getParameters().get('caseIdentifierId');


        ShGl_PostChatSurvey__c postChatSurvey = new ShGl_PostChatSurvey__c(); 
        postChatSurvey.ShGl_SurveyQuestion1__c = question1;
        postChatSurvey.ShGl_SurveyQuestion2__c = question2;
        postChatSurvey.ShGl_SurveyQuestion3__c = question3;
        postChatSurvey.ShGl_SurveyQuestion4__c = question4;
        postChatSurvey.ShGl_SurveyResponse1__c = questionAnsSelected1; 
        postChatSurvey.ShGl_SurveyResponse2__c = questionAnsSelected2; 
        postChatSurvey.ShGl_SurveyResponse3__c = questionAnsSelected3; 
        postChatSurvey.ShGl_SurveyResponse4__c = questionAnsSelected4; 
        postChatSurvey.ShGl_Market_Code__c = 'US'; //new data base model
        postChatSurvey.ShGl_UniqueCaseIdentifier__c = CaseIdentifierIdValue;
        //postChatSurvey.ShGl_LiveTranscriptChatKey__c = chatKeyIdValue;
        //postChatSurvey.ShGl_CaseOfSurvey__c = (Id) LiveChatTranscriptObj.CaseId;   //through trigger     
        Database.SaveResult postSaveResult = Database.insert(postChatSurvey);
        return new PageReference('javascript:window.close();');
}

提前致谢。

任何帮助,将不胜感激。

salesforce apex apex-code visualforce salesforce-service-cloud
1个回答
1
投票

当您查看Window.close()的文档时,您会找到原因:

仅允许对使用window.open()方法由脚本打开的窗口调用此方法。如果脚本未打开窗口,则控制台中会出现类似于此窗口的错误:脚本可能无法关闭脚本未打开的窗口。

简而言之:浏览器不会让你。这不是特定于Salesforce或VF。无论如何,Windows.close()不会关闭选项卡,而是整个浏览器窗口。

如果您要关闭控制台选项卡,this question/answer可能会提供您要查找的内容。

© www.soinside.com 2019 - 2024. All rights reserved.