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?
TIA
Solved! Go to Solution.
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", "");
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", "");
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!
Add an OnClick Event on this Image.
e.g
dojo.connect(statsLink2, "onclick", FunctionName);