Select to view content in your preferred language

Issues adding a hyperlink to resultGraphic in popupTemplate

636
7
Jump to solution
04-13-2023 12:26 PM
TristanG
New Contributor II

I have 2 arrays of <a> tags, one has an href attribute, and the other has an onclick attribute. When the <a> arrays are carried into the popupTemplate, it always clears all the attributes but keeps the text within <a></a>, rendering the link unusable or incorrect.

0 Kudos
1 Solution

Accepted Solutions
JoelBennett
MVP Regular Contributor

Have you seen this thread? You'll find various proposed solutions to this kind of problem there.

View solution in original post

0 Kudos
7 Replies
KenBuja
MVP Esteemed Contributor

Can you post your code?

0 Kudos
TristanG
New Contributor II

Here are some snippets of the relevant pieces of code:

this is within a large for loop, so all the links in this array is set to thisthis is within a large for loop, so all the links in this array is set to this

showresult example.PNG

what the popup looks likewhat the popup looks like

what it looks like in consolewhat it looks like in console

0 Kudos
KenBuja
MVP Esteemed Contributor

What are you expecting when someone clicks on "Test"? If it's opening up another site, then this works (using this sample)

var linkArray = [
  "<a href='http://google.com'>Test</a>",
]
const polylineGraphic = new Graphic({
  geometry: polyline,
  symbol: lineSymbol,
  attributes: lineAtt,
  popupTemplate: {
  // autocasts as new PopupTemplate()
    title: "{Name}",
    content: linkArray[0]
  }
});

 

popup3.png

0 Kudos
TristanG
New Contributor II

So the links I am grabbing from an underlying webpage, has links that look like(which is supposed to get copy and pasted into the popupbox):

<a href='' onclick='alert()'>Test</a>

^This one is supposed to open an alert() dialogue box in the browser.

<a href='javascript&colon;linkTest();'>Test</a> (&colon; is supposed to just be a normal colon but the forum is changing it to &colon;)

^This one is supposed to bring a user to a new website using a javascript function, as it returns a link that is dynamically generated

The main issue that I am having, is that it seems to remove all of the attributes, if it isn't a normal link like what you did above.

0 Kudos
TristanG
New Contributor II

by what I mean by "copy and pasted", I grabbed all the links and stored them into an array, to be displayed into the popupBox

0 Kudos
JoelBennett
MVP Regular Contributor

Have you seen this thread? You'll find various proposed solutions to this kind of problem there.

0 Kudos
TristanG
New Contributor II

Thanks for the pointer! I swear I was looking everywhere up and down, but I just wasn't using the right phrasing. This immediately helped!

0 Kudos