email link

1904
3
Jump to solution
07-25-2012 01:02 PM
VernWolfley
New Contributor III
I am trying to add an email link into a popup.  The email link will send feature data about the point selected when someone clicks it.  It is working but, every time a new point is click a new link is added to the bottom of the popup.  How do I overwrite the link each time a point is clicked?  here is the code I have for the link.
//*** Email Link ***//         dojo.connect(map, 'executeIdentifyTask', function (result) {             // Add a link into the InfoWindow Actions panel                   var emailLink = dojo.create("a", {             "class": "action email",             "innerHTML": "Email Comments",             "href": "javascript:void(0);"             }, dojo.query(".actionList", map.infoWindow.domNode)[0]);         console.log(emailLink);              // Register a function to be called when the user clicks on             // the above link             dojo.connect(emailLink, "onclick", function (evt) {                 var feature = map.infoWindow.getSelectedFeature();                 var url = window.location;                 var emailLink = "mailto:emailaddress@email.com?subject=Comments:%20" + feature.attributes.ID + "&body=Comments on Landmark:%20ID:%20"+ feature.attributes.ID +" @ " + window.location;                 window.location.href = emailLink;             });          });

Thanks
0 Kudos
1 Solution

Accepted Solutions
AlanRussian
New Contributor III

Hey, Vern,

I've modified your code to create a container element if it doesn't already exist and then add the link after emptying the container.

        //*** Email Link ***//
        dojo.connect(map, 'executeIdentifyTask', function (result) {
          if (!dojo.byId("emailLink")) {
            dojo.create("span", {
              id: "emailLink"
            }, dojo.query(".actionList", map.infoWindow.domNode)[0]);
            // Add a link into the InfoWindow Actions panel
            var emailLink = dojo.create("a", {
              "class": "action email",
              "innerHTML": "Email Comments",
              "href": "javascript:void(0);"
            }, "emailLink", "only");
            console.log(emailLink);
            // Register a function to be called when the user clicks on
            // the above link
            dojo.connect(emailLink, "onclick", function (evt) {
              var feature = map.infoWindow.getSelectedFeature();
              var url = window.location;
              var emailLink = "mailto:emailaddress@email.com?subject=Comments:%20" + feature.attributes.ID + "&body=Comments on Landmark:%20ID:%20" + feature.attributes.ID + " @ " + window.location;
              window.location.href = emailLink;
            });
          }
        });

Let me know if it doesn't work out for you.

--Alan

View solution in original post

0 Kudos
3 Replies
AlanRussian
New Contributor III

Hey, Vern,

I've modified your code to create a container element if it doesn't already exist and then add the link after emptying the container.

        //*** Email Link ***//
        dojo.connect(map, 'executeIdentifyTask', function (result) {
          if (!dojo.byId("emailLink")) {
            dojo.create("span", {
              id: "emailLink"
            }, dojo.query(".actionList", map.infoWindow.domNode)[0]);
            // Add a link into the InfoWindow Actions panel
            var emailLink = dojo.create("a", {
              "class": "action email",
              "innerHTML": "Email Comments",
              "href": "javascript:void(0);"
            }, "emailLink", "only");
            console.log(emailLink);
            // Register a function to be called when the user clicks on
            // the above link
            dojo.connect(emailLink, "onclick", function (evt) {
              var feature = map.infoWindow.getSelectedFeature();
              var url = window.location;
              var emailLink = "mailto:emailaddress@email.com?subject=Comments:%20" + feature.attributes.ID + "&body=Comments on Landmark:%20ID:%20" + feature.attributes.ID + " @ " + window.location;
              window.location.href = emailLink;
            });
          }
        });

Let me know if it doesn't work out for you.

--Alan

0 Kudos
VernWolfley
New Contributor III
Thanks Alen that did the trick, just what I was looking for.
0 Kudos
AlanRussian
New Contributor III
You're welcome!  Happy to help.
0 Kudos