AnsweredAssumed Answered

Executing JavaScript from Popup media linkURL

Question asked by vandervoort on Sep 6, 2016
Latest reply on Jul 11, 2019 by Lizd711

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": "",
            "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="" style="margin-top: 53px;">

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"?