'Hyperlink on a Graphic element in ArcGis

i need your help please.

I would like to be able to click on a point added on an ArcGis map so that when I click on it I am redirected to another web page

I have been following the tutorials: https://developers.arcgis.com/javascript/latest/display-a-map/

  • Display a map
  • Add a point
  • add a feature layer
  • Display a popup

This is the code so far:

require([
    "esri/config",
    "esri/Map",
    "esri/views/MapView",
    "esri/Graphic",
    "esri/layers/GraphicsLayer",
    "esri/layers/FeatureLayer"
    
    


], function(esriConfig,Map, MapView, Graphic, GraphicsLayer, FeatureLayer) {

    esriConfig.apiKey = "YOUR_KEY";

    const map = new Map({
      basemap: "arcgis-topographic"
    });

    const view = new MapView({
      container: "DivCarte",
      map: map,
      center: [-83.54500,19.02700],
      zoom: 6
    });


    const graphicsLayer = new GraphicsLayer();
    map.add(graphicsLayer);
    
    
    const point = { //Create a point
        type: "point",
        longitude: -86.900000,
        latitude: 21.201278
     };
     const simpleMarkerSymbol = {
        type: "simple-marker",
        color: [226, 119, 40],  // Orange
        outline: {
            color: [255, 255, 255], // White
            width: 1
        }
     };
     
     
    const popupTemplate = {
        title: "Cancun",
        content: "<a href=http://travelwithnico.com>Site</a>"
    }
     
     
     const attributes = {
        Name: "AttGraphic",
        Description: "Ilalala"
    }
     
     
  
     const pointGraphic = new Graphic({
        geometry: point,
        symbol: simpleMarkerSymbol,
        attributes: attributes,
        popupTemplate: popupTemplate
        
     });
     
     
     
     graphicsLayer.add(pointGraphic);

I managed to open a popup showing the link but it opens on a new tab. How can I force it to move to the link in the same window?

Thank you for your help.

Nico



Solution 1:[1]

Have you tried inlining a JavaScript inside an onclick event? Something like this:

...
content: '<a href="#" onclick="javascript:document.location.href=\'http://travelwithnico.com\'">Site</a>'
...

I'm not sure if this will work, but it worths trying.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Carlos Nantes