Newer Version Available

This content describes an older version of this product. View Latest

setTabIcon()

Usage

Sets an icon on the specified tab. If a tab is not specified, the icon is set on the enclosing tab. Use this method to customize a tab’s icon. This method is only available in API version 28.0 or later.

Syntax

1sforce.console.setTabIcon(iconUrl:String, tabID:String, (optional)callback:Function)

Arguments

Name Type Description
iconUrl string A URL pointing to an image, which is used as the tab’s icon. If null or undefined, the tab’s default icon is used.
tabId string The ID of the tab on which to set the icon. If null or undefined, the enclosing tab’s ID is used.
callback function JavaScript method called upon completion of the method.

Sample Code–Visualforce

1swfobject.registerObject("clippy.codeblock-1", "9");<apex:page>
2    <A HREF="#" onClick="testSetTabIcon();return false">
3         Click here to change the enclosing tab’s icon</A> <BR/>
4    <A HREF="#" onClick="testResetTabIcon(); return false;">
5         Click here to reset the enclosing tab’s icon</A>
6
7    <apex:includeScript value="/support/console/28.0/integration.js"/>
8    <script type="text/javascript">
9        function checkResult(result) { 
10            if (result.success) {
11               alert('Tab icon set successfully!');
12            } else {
13               alert('Tab icon cannot be set!');
14            }
15    }
16        function testSetTabIcon() {
17            sforce.console.setTabIcon('http://host/path/to/your/icon.png', null, checkResult);
18    }
19        function testResetTabIcon() {
20            sforce.console.setTabIcon(null, null, checkResult);
21    }
22    </script>
23</apex:page>

Response

This method is asynchronous so it returns its response in an object in a callback method. The response object contains the following field:

Name Type Description
success boolean true if setting the tab’s icon was successful, false if setting the tab’s icon wasn’t successful.

If this method is called without passing in a tab ID, the tab in which the Visualforce page is enclosed is used. If there isn’t an enclosing tab, the error message Cannot get a workspace or view tab from the given ID displays in the browser’s developer console.

Note