AnsweredAssumed Answered

Executing JavaScript from Popup media linkURL

Question asked by vandervoort on Sep 6, 2016
Latest reply on Sep 7, 2016 by ppapadopoulosmarathondata-gr-esridist

I have a custom Popup that displays an image using the sourceURL. I'd like the linkURL to fire some JavaScript code. The mediaInfos in the PopupTemplate looks like this:

      "mediaInfos": [
        {
          "title": "",
          "type": "image",
          "caption": "",
          "value": {
            "sourceURL": "http://webapps-cdn.esri.com/Apps/MegaMenu/img/logo.jpg",
            "linkURL": "javascript:void(alert('Just fire an alert.'))"
         }
        }
      ]

Unfortunately, in Firefox and IE, when the user clicks the image, a new web browser tab is opened and the javascript gets executed inside the new browser tab. This is not the case in Chrome.

 

When you inspect the media element in the browser you see the anchor tag get constructed like this:

<a href="javascript:void(alert('Just fire an alert.'))" target="_blank">
<img class="esriPopupMediaImage" src="http://webapps-cdn.esri.com/Apps/MegaMenu/img/logo.jpg" style="margin-top: 53px;">
</a>

Note that the <a/> tag includes the parameter target="_blank", which tells the the browser to open the href in a new browser.

 

In Firebug, if I delete the target="_blank" parameter from the anchor tag, the Javascript executes inside the same browser window as the popup. This is the desired behavior.

 

My question is: how can I get rid of that target="_blank" parameter? 

  • In the PopupTemplate mediaInfos? If so, how? In the javascript:void?
  • Is there a global override of target="_blank"?

 

TIA

Outcomes