Select to view content in your preferred language

Click on feature, open hyperlink... Any Suggestions?

951
4
06-03-2014 07:09 AM
ChristopherCarr
Occasional Contributor
I'm looking for any leads from anyone who has used an onclick event to directly open a hyperlink (stored as an attribute) instead of opening a popup window.  I'm currently using the tooltip on hover and want to open a hyperlink on click.  Any help would be greatly appreciated!
0 Kudos
4 Replies
JakeSkinner
Esri Esteemed Contributor
Hi Christopher,

You could do the following:

var featureLayer = new FeatureLayer(<service url>,{
    mode: FeatureLayer.MODE_ONDEMAND,
    outFields: ["*"]
});  

on(featureLayer, "click", function(evt){
  url = evt.graphic.attributes.<field name>;
  window.open(url);
})
0 Kudos
ChristopherCarr
Occasional Contributor
JSkinn3, thanks for the info.  I'm actually using non-AMD modules trying to rewrite it to match my application.  I've tried giving it a try, but can't figure out where I'm going wrong.  Any help would be appreciated! 

var featureLayer = new esri.layers.FeatureLayer(<service url>,{
  mode: esri.layers.FeatureLayer.MODE_ONDEMAND,
  outFields: ["*"],
});

        
featurelayer.on("click", openHyperlink);

        
function openHyperlink(evt){
  url = evt.graphic.attributes.<field name>;
  window.open(url);
}


Hi Christopher,

You could do the following:

var featureLayer = new FeatureLayer(<service url>,{
    mode: FeatureLayer.MODE_ONDEMAND,
    outFields: ["*"]
});  

on(featureLayer, "click", function(evt){
  url = evt.graphic.attributes.<field name>;
  window.open(url);
})
0 Kudos
JakeSkinner
Esri Esteemed Contributor
Try the following:

var featureLayer = new esri.layers.FeatureLayer(<service url>,{
  mode: esri.layers.FeatureLayer.MODE_ONDEMAND,
  outFields: ["*"],
});

        
dojo.connect(featureLayer, "onClick", openHyperlink);

        
function openHyperlink(evt){
  url = evt.graphic.attributes.<field name>;
  window.open(url);
}
0 Kudos
ChristopherCarr
Occasional Contributor
JSkinn3, thank you so much!  This worked beautifully!
0 Kudos