0

基本的にCMSシステムへのビューであるVFページがあります。汎用 ID でログインし、Web サービスを使用してファイルのリストを取得および表示できます。ここで、ファイルをクリックして新しいウィンドウで開くことができるようにしたいと考えています。ファイルのバイト ストリームを返す CMS Web サービスがあります。そのストリームをブラウザに返すように Apex リモートアクションを設定するにはどうすればよいですか? さらに、これを新しいタブで開くにはどうすればよいですか?

次のような削除アクションが必要です。

public static HttpResponse sendRequest(String endpoint, String method)
{
    HttpRequest req = new HttpRequest();
    req.setMethod(method);
    req.setEndpoint(endpoint);

    HttpResponse resp;
    if (Test.isRunningTest())
    {
        resp = new HttpResponse();
        resp.setBody('');
    }
    else
    {
        Http http = new Http();
        resp = http.send(req);
    }

    return resp;
}


@RemoteAction
public static HttpResponse open(docid)
{
    return sendRequest(API_DOMAIN + '/ws/open/' + docid + '/', 'GET');
}

次に、UI 側で:

MainBehavior.Open= function(docid) {
    Visualforce.remoting.Manager.invokeAction(
        '{!$RemoteAction.ResourceCenterController.open}',
                    docid,
        function(result, event)
        {
            if (event.status)
            {
                 return result;
            } 
            else if (event.type === 'exception') 
            {
                alert('Not able to open!\n\n' + event.message);
            }
            else
            {
                alert('Not able to open!');
            }
        }
    );

そして後でクリックイベントで:

window.open(MainBehavior.Open(docid), '_blank');

このコードがそのままでは機能しないことはわかっていますが、これが私の目標です。これをどうするかについての提案はありますか?

4

1 に答える 1

-1
if (event.status) {
 // window.open(result,'_blank'); //file in new window
 window.location.href =result;    //file in same window
}

この行はファイルを開きます。新しいウィンドウで開くことは避けてください。AdBlockers は、ほとんどのブラウザーで JS を介して開かれた新しいウィンドウをブロックします。

于 2013-08-09T09:51:28.627 に答える