openSubtab()
指定された URL (相対または絶対) のコンテンツを表示する新しいサブタブ (主タブ内) を開きます。また、既存のサブタブを上書きすることもできます。主タブの ID を使用して主タブで新しいサブタブを開く場合に使用します。このメソッドは、API バージョン 20.0 以降でのみ使用できます。
タブを開くときにエラーが発生した場合、JavaScript コンソールでエラーコードがレポートされます。
構文
1sforce.console.openSubtab(primaryTabId:String, url:URL, active:Boolean, tabLabel:String, id:String, (optional)callback:Function, (optional)name:String)引数
サンプルコード – Visualforce
1swfobject.registerObject("clippy.codeblock-1", "9");
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17<apex:page standardController="Case">
18
19 <A HREF="#" onClick="testOpenSubtab();return false">
20 Click here to open a new subtab</A>
21
22 <apex:includeScript value="/support/console/22.0/integration.js"/>
23 <script type="text/javascript">
24 function testOpenSubtab() {
25 //First find the ID of the primary tab to put the new subtab in
26 sforce.console.getEnclosingPrimaryTabId(openSubtab);
27 }
28
29 var openSubtab = function openSubtab(result) {
30 //Now that we have the primary tab ID, we can open a new subtab in it
31 var primaryTabId = result.id;
32 sforce.console.openSubtab(primaryTabId , 'http://www.salesforce.com', false,
33 'salesforce', null, openSuccess, 'salesforceSubtab');
34 };
35
36 var openSuccess = function openSuccess(result) {
37 //Report whether we succeeded in opening the subtab
38 if (result.success == true) {
39 alert('subtab successfully opened');
40 } else {
41 alert('subtab cannot be opened');
42 }
43 };
44 </script>
45</apex:page>応答
このメソッドは非同期であるため、コールバックメソッドのオブジェクトで応答を返します。応答オブジェクトには次の項目が含まれます。
| 名前 | 型 | 説明 |
|---|---|---|
| success | boolean | サブタブが正常に開かれた場合は true、サブタブが開かれなかった場合は false。 |
| id | string | サブタブの ID。ID はユーザセッションの間のみ有効です。ユーザが Salesforce コンソールから離れると ID は無効になります。 |