You are using a browser that is no longer supported. Please use the latest version of Google Chrome, Mozilla Firefox, Apple Safari, or Microsoft Edge. For more information please see the System Requirements.
Skip To ContentArcGIS for DevelopersSign In Dashboard

Unsupported browser

You are using a browser that is not supported. JavaScript API works on the latest versions of Google Chrome, Mozilla Firefox, Apple Safari, or Microsoft Edge. Use one of these browsers and provide your feedback through GeoNet, the Esri Community.

  • {}
  • Firefox
  • Safari
  • undefined

Note: Support for 3D on mobile devices may vary, view the system requirements for more information.

It is possible to customize Popup and PopupTemplate actions per feature attribute.

This sample demonstrates how to format custom actions specifically per selected feature. It uses a Popup and a PopupTemplate. Although actions can be added via the actions property on either the Popup or PopupTemplate, the actions in this sample are specifically set within the featurelayer's popupTemplate.

popupTemplate: {
  actions: [
      id: "find-brewery",
      image: "beer.png",
      title: "Brewery Info"

Actions are styled by either using the class or image property. If using class, you must use an icon font. If using image, you must provide a valid URL to an image that will be used as a background-image for the action. In this specific example, an image is used to indicate the action button.

How it works

First, watch for the Popup's selectedFeature property. Next, set the action's visible property to true if the feature's website value isn't null, otherwise set it to false."selectedFeature", function(graphic) {
  if (graphic) {
    var graphicTemplate = graphic.getEffectivePopupTemplate();
    graphicTemplate.actions.items[0].visible = ? true : false;

The PopupViewModel's trigger-action is fired and then checks for the action ID. In this case, it's listening for an ID called find-brewery.

popup.viewModel.on("trigger-action", function(event) {
  if ( === "find-brewery") {
    // do something

Next, it grabs the attributes of the selected feature. We don't need all of them, so in this example we explicitly grab the attribute with the name website and store it in a new variable called info.

var attributes = popup.viewModel.selectedFeature.attributes;
// Get the 'website' field attribute
var info =;

After this, we check to make certain this value is not null. If not, some string manipulation is performed and the URL value stored within the website field is opened up in a new browser window. Otherwise, a message is displayed in the console window.

  // Make sure the 'website' attribute value is not null
  if (info) {
    // Open up a new browser using the URL value in the 'website' field;

Sample search results