14

商談の詳細ページに埋め込まれた Visualforce ページがあります。

ページ内には、バッキング コントローラー拡張機能のメソッドを呼び出すコマンド ボタンがあります。

バッキング メソッドが完了したら、ユーザーを別のページにリダイレクトするにはどうすればよいですか?

メソッドから PageReference を返すことはできますが、埋め込まれた Visualforce ページが表示される iframe のみをリダイレクトします。

理想的には最上位ウィンドウを更新したいのですが、埋め込まれた Visualforce ページが親ウィンドウと同じドメインにない場合、クロスドメインの問題が発生する可能性があるのではないかと心配しています。


基本的なテストとして、埋め込まれた Visualforce ページに以下を追加してみました。

<script>
    window.setTimeout(testRedirect,2000);
    function testRedirect() {
        top.location.reload();
    }
</script>

これにより、Chrome でエラーがログに記録されました。

安全でない JavaScript が、URL https://ab2.na2.visual.force.com/servlet/servlet.Integration?lid=066400000000000&ic=1 のフレームから URL https://na2.salesforce.com/006400000000000 のフレームにアクセスしようとし ます。ドメイン、プロトコル、およびポートが一致する必要があります。

そのため、Visualforce ページのドメインは異なります。

4

3 に答える 3

15

もう少しコードが長くなりますが、これはすべてのブラウザーで機能し、クロスドメイン エラーは発生しません。

コントローラ拡張:

public class Opp_Ext {
    private ApexPages.StandardController stdController;
    public String redirectUrl {public get; private set;}
    public Boolean shouldRedirect {public get; private set;}

    public Opp_Ext(ApexPages.StandardController stdController) {
        this.stdController = stdController;
        shouldRedirect = false;
    }

    public PageReference doStuffAndRedirect() {
        shouldRedirect = true;
        redirectUrl = stdController.view().getUrl();
        return null;
    }
}

VF ページ:

<apex:page standardController="Opportunity" extensions="Opp_Ext" >
    <apex:form >
        <apex:commandButton value="Do Stuff" action="{!doStuffAndRedirect}" rerender="redirectPanel" />
        <apex:outputPanel id="redirectPanel" >
            <apex:outputText rendered="{!shouldRedirect}">
                <script type="text/javascript">
                    window.top.location.href = '{!redirectUrl}';
                </script>
            </apex:outputText>
        </apex:outputPanel>
    </apex:form>
</apex:page>
于 2012-07-19T12:41:01.847 に答える
0

PageReference Classを使ってみる

さらに、setRedirect が役立ちます

サンプル:

public class mySecondController {
Account account;

public Account getAccount() {
    if(account == null) account = new Account();
    return account;
}

public PageReference save() {
    // Add the account to the database.  

    insert account;
    // Send the user to the detail page for the new account. 

    PageReference acctPage = new ApexPages.StandardController(account).view();
    acctPage.setRedirect(true);
    return acctPage;
}

}

于 2012-07-19T12:31:32.670 に答える
-1

使用する必要がありますoncomplete = "window.top.location.href = '{!'/'+obj.id}';"

于 2017-01-04T19:43:14.807 に答える