I have some Webmaps with custom popups that contain hyperlinks, some of which should display information that is relevant to doing other things in the map - but these popups always open the link in another tab. I hate tabs for the simple reason that I can only see one at a time, thus hiding the map. This is simple enough to do in HTML, but how do you do this in an Arcade expression?
Solved! Go to Solution.
When you add a text element, click the source <> icon to edit in html. See the tip on this documentation page:
However this actually won't work the way you want it to, ever.
https://doc.arcgis.com/en/arcgis-online/reference/supported-html.htm
When an a tag is used, the href target URL always opens in a new browser tab.
I thought it might be enforced by end users browser's but it looks like this is also enforced by ArcGIS.
You can return html within a popup. Add a text or arcade section your popup and then:
Here's an example arcade snipped that could be used:
var url = $feature["URL_Field"];
return "<a href='" + url + "' target='_blank' onclick=\"window.open(this.href, 'newwindow', 'width=800,height=600'); return false;\">Open link</a>";
Genius! Thank you for the reply. I must be missing something though:
When I put the expression in a text element, it just puts the HTML string in the popup so I tried the Arcade element which did produce a working hyperlink, but it seems to ignore the javascript in there and just open the page in another tab. Here's the expression I made:
var inParam = $feature["wmext_Pole_JPA"];
if (IsEmpty(inParam)) {return ""};
var base_url = "https://scjpc.net/search/jpa/details/";
inParam = Replace(inParam, '-', '');
inParam = Replace(inParam, ' ', '');
inParam = Replace(inParam, '/', '');
base_url = base_url + inParam;
var returntxt = "<a href='" + base_url + inParam + "' target='_blank' onclick=\"window.open(this.href, 'newwindow', 'width=800,height=600'); return false;\">HTML</a>";
return {
type : 'text',
text : returntxt //this property supports html tags
}
When you add a text element, click the source <> icon to edit in html. See the tip on this documentation page:
However this actually won't work the way you want it to, ever.
https://doc.arcgis.com/en/arcgis-online/reference/supported-html.htm
When an a tag is used, the href target URL always opens in a new browser tab.
I thought it might be enforced by end users browser's but it looks like this is also enforced by ArcGIS.
Thanks for those links. I did follow that tip and used the source button, but just got the HTML string.
Most browsers default to opening things in tabs, but I set mine to open in new windows, so is enforced by ArcGIS, but additionally I don't think you can embed Javascript in the HTML. Just for grins I tried this
<H1 onclick="alert('clicked'); " ############################## </H1>
and it didn't work either.
Bummer.....