Executing JavaScript from Popup media linkURL

1618
3
Jump to solution
09-06-2016 02:37 PM
DirkVandervoort
Occasional Contributor II

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

0 Kudos
1 Solution

Accepted Solutions
FC_Basson
MVP Regular Contributor

Find the element reference for the anchor link in the popup and set the target attribute to nothing when the popup opens:

link.setAttribute("target", "");

View solution in original post

3 Replies
FC_Basson
MVP Regular Contributor

Find the element reference for the anchor link in the popup and set the target attribute to nothing when the popup opens:

link.setAttribute("target", "");
LizDaRos
Occasional Contributor

Any chance you can go into more detail where to add this line of code? I'm new to editing the WAB code and there are so many different files.

Thanks!

0 Kudos
PanagiotisPapadopoulos
Esri Regular Contributor

Add an OnClick Event on this Image.

e.g

dojo.connect(statsLink2, "onclick", FunctionName);

0 Kudos