Select to view content in your preferred language

Hyperlink in Popup to open in new window

1251
4
Jump to solution
09-20-2024 02:54 PM
Pukawai
Occasional Contributor

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?

Tags (1)
1 Solution

Accepted Solutions
ChristopherCounsell
MVP Regular Contributor

When you add a text element, click the source <> icon to edit in html. See the tip on this documentation page:

https://doc.arcgis.com/en/arcgis-online/create-maps/configure-pop-ups-mv.htm#ESRI_SECTION1_B7B559DA3...

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.

View solution in original post

0 Kudos
4 Replies
ChristopherCounsell
MVP Regular Contributor

You can return html within a popup. Add a text or arcade section your popup and then:

  • Text (use the <> when configuring to open html editor)
  • Text (add {expression/expr0} referencing the arcade expression returning html)
  • Arcade (configure the expression to return html)

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

0 Kudos
Pukawai
Occasional Contributor

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 
}
0 Kudos
ChristopherCounsell
MVP Regular Contributor

When you add a text element, click the source <> icon to edit in html. See the tip on this documentation page:

https://doc.arcgis.com/en/arcgis-online/create-maps/configure-pop-ups-mv.htm#ESRI_SECTION1_B7B559DA3...

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.

0 Kudos
Pukawai
Occasional Contributor

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.....